您的位置:首页 > 运维架构 > Linux

Linux下find使用方法介绍

2007-10-31 23:58 701 查看
1. Find 查找文件内容
比如:查找 test.c文件
Find / -name test.c –
find /tmp -name core -type f -print0 | xargs -0 /bin/rm –f

find . -name '*.c' -type f -print0 |xargs -0 grep -n 'printf'
在当前目录下查找.c的文件,并在所有查找出来的文件中查找printf这个单词,并将行号输出

-print0
True; print the full file name on the standard output, followed by a null character (instead of the newline character that ‘-print’ uses). This allows file names that contain newlines or other types of white space to be correctly interpreted by programs that processthe find output. This option corresponds to the ‘-0’ option ofxargs.
-print
True; print the full file name on the standard output, followed bya newline. If you are piping the output of find into another pro-gram and there is the faintest possibility that the files which youare searching for might contain a newline, then you should seri-ously consider using the ‘-print0’ option instead of ‘-print’. Seethe UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled.

-type Supported. POSIX specifies ‘b’, ‘c’, ‘d’, ‘l’, ‘p’, ‘f’ and ‘s’. GNU find also supports ‘D’, representing a Door, where the OS pro-vides these.

xargs - build and execute command lines from standard input
--null, -0
Input items are terminated by a null character instead of by
whitespace, and the quotes and backslash are not special (every
character is taken literally). Disables the end of file string,
which is treated like any other argument. Useful when input items
might contain white space, quote marks, or backslashes. The GNU
find -print0 option produces input suitable for this mode.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: