Thursday, 11 September 2008

Find command: '-exec' action

There is a way to execute a command on each file using find and it is done with the -exec action argument.

For example, removing all backup files under the '/' directory and its subdirectories is done like this:

$ find / -name '*~' -exec rm '{}' \;


This means: execute rm command on each filename that ends with '~' on file system. The '{}' part of the command is replaced with the filenames that are found during execution, and escaped semicolon (\;) at the end represents the end of the -exec action argument.

No comments: