2011年8月7日 星期日

linux find command

find command:
;find string in current folder all files
#find . -exec grep 'test' {} \;
*{}: this list all files
*\ : this is ending word

The -exec action takes a Unix command (along with its options) as an argument.
The arguments should contain {} (usually quoted), which is replaced in the command with the name of the currently found file.
The command is terminated by a semicolon, which must be quoted ("escaped") so the shell will pass it literally to the find command.


;rm file in current folder all files
#find . -name oo.txt -print -exec rm -f {} \;

;find 00.txt file only looking for file under this folder
#find . -name oo.txt -type f

;find 00.txt file only looking for folder type under this folder
#find . -name 00.txt -type d


using xargs command in find command
#find whatever....| args commnad

xargs is command to execute commnd line from standard input.

;list file
#find . -name xx.txt -print | xargs ls -l

;rmmove files from test folder
#find ./test -type f -print0 | xargs -0 rm

more information in "http://en.wikipedia.org/wiki/Xargs"

沒有留言:

張貼留言