Running Commands on the Files You Find

You can also use find to execute a command you specify on each found file, by giving the command as an argument to the `−exec' option. If you use the string `'{}'' in the command, this string is replaced with the file name of the current found file when the command executes. Mark the end of the command with the string `';''.

To find all files in the `~/html/' directory tree with an `.html' extension, and output lines from these files that contain the string `organic', type:

$ find ~/html/ −name '*.html' −exec grep organic '{}' ';' RET

In this example, the command grep organic file is executed for each file that find finds, with file being the name of each file in turn. To have find pause and confirm execution for each file it finds, use `−ok' instead of `−exec'. · To remove files from your home directory tree that were accessed more than one year after they were last modified, pausing to confirm before each removal, type:

$ find ~ −used +365 −ok rm '{}' ';' RET

Posted on: 16/12/2009








0 Comments
If you want to leave a comment please Login or Register
How to backup your data using rsync......
Understanding autoconf......
The Basics of fdisk......
Accessing Memory Using DMA......
The fd Directory......