

While xargs executes the command at once for all the matched files. If we use the –exec command to remove the files, it will remove them file by file. Contrary to xargs, – exec executes the command every time a file matches the condition. It can execute commands based on the output of the first command. The previous ls command shows the existing files before executing find, and the second ls shows the result with all the “.txt” files deleted.Īs you can see, the ls ~/dir1/* result was passed by xargs after the mv command. You can see the command in the third line of the following figure. In this case, we will replace the – delete option with the -exec rm again to delete all the “.txt” files as we did in the second example of this document but using a different technique. As you can see, there are different “.txt” files. Now, let’s see a new scenario using the ls command again.

Our case is in the home directory, therefore this dot is equal to /home/user. (Dot): The dot after the find command specifies that the operation must be done within the current directory.
