Combining other commands with the find command

You can also use the find command to find a file and then carry out a command on that file. To do this use the command:

   find pathname -name filename -print -exec command {}\;

To be prompted for confirmation before the command is executed use the command:

   find pathname -name filename -print -ok command {}\;

The command must be followed by a \ (backslash) and a ; (semi-colon). The {} (pair of braces) substitute the pathname of the file that is found as an argument to the command.

Its worth noting that the above techniques will execute command once per file. If you prefer to run the command on several files at once, the xargs command is worth knowing:

   find pathname -name filename -print | xargs command 

[Home] [Search] [Index] This site maintained by guide@cs.mcgill.ca