Linux中find常见用法示例

来源:互联网 发布:压缩密码破解软件 编辑:程序博客网 时间:2024/05/22 12:26

find命令的参数;

find path -option [-print][ -exec -ok command ] {} \; #注意{}\之间的空格

pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为’command’ { } \;,注意{ }和\;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。

例:find . -name .svn | xargs rm -rf-name   filename             #查找名为filename的文件-perm                        #按执行权限来查找-user    username             #按文件属主来查找-group groupname            #按组来查找-mtime   -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前-atime    -n +n               #按文件访问时间来查GIN: 0px">-ctime    -n +n              #按文件创建时间来查找文件,-n指n天以内,+n指n天以前-nogroup                     #查无有效属组的文件,即文件的属组在/etc/groups中不存在-nouser                     #查无有效属主的文件,即文件的属主在/etc/passwd中不存-newer   f1 !f2              找文件,-n指n天以内,+n指n天以前 -ctime    -n +n               #按文件创建时间来查找文件,-n指n天以内,+n指n天以前 -nogroup                     #查无有效属组的文件,即文件的属组在/etc/groups中不存在-nouser                      #查无有效属主的文件,即文件的属主在/etc/passwd中不存-newer   f1 !f2               #查更改时间比f1新但比f2旧的文件-type    b/d/c/p/l/f         #查是块设备、目录、字符设备、管道、符号链接、普通文件-size      n[c]               #查长度为n块[或n字节]的文件-depth                       #使查找在进入子目录前先行查找完本目录-fstype                     #查更改时间比f1新但比f2旧的文件-type    b/d/c/p/l/f         #查是块设备、目录、字符设备、管道、符号链接、普通文件-size      n[c]               #查长度为n块[或n字节]的文件-depth                       #使查找在进入子目录前先行查找完本目录-fstype                      #查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到-mount                       #查文件时不跨越文件系统mount点-follow                      #如果遇到符号链接文件,就跟踪链接所指的文件-cpio                %;      #查位于某一类型文件系统中的文件,这些文件系统类型通常可 在/etc/fstab中找到-mount                       #查文件时不跨越文件系统mount点-follow                      #如果遇到符号链接文件,就跟踪链接所指的文件-cpio                        #对匹配的文件使用cpio命令,将他们备份到磁带设备中-prune                       #忽略某个目录

例子

$find ~ -name "*.txt" -print    #在$HOME中查.txt文件并显示$find . -name "*.txt" -print$find . -name "[A-Z]*" -print   #查以大写字母开头的文件$find  /etc -name "host*" -print #查以host开头的文件$find . -name "[a-z][a-z][0–9][0–9].txt" -print  #查以两个小写字母和两个数字开头的txt文件$find . -perm 755 -print$find . -perm -007 -exec ls -l {} \; #查所有用户都可读写执行的文件同-perm 777$find . -type d -print$find . ! -type d -print $find . -type l -print$find . -size +1000000c -print  #查长度大于1Mb的文件$find . -size 100c  -print      #查长度为100c的文件$find . -size +10c -print       #查长度超过期作废10块的文件(1块=512字节)
#来自man find -size n[cwbkMG]              File uses n units of space, rounding up.  The              following suffixes can be used:              `b'    for  512-byte  blocks  (this  is   the                     default if no suffix is used)              `c'    for bytes              `w'    for two-byte words              `k'    for Kilobytes (units of 1024 bytes)              `M'    for Megabytes (units of 1048576 bytes)              `G'    for  Gigabytes  (units  of  1073741824                     bytes)              The size does not count indirect blocks,  but              it does count blocks in sparse files that are              not actually allocated.  Bear  in  mind  that              the   `%k'  and  `%b'  format  specifiers  of              -printf handle sparse files differently.  The              `b' suffix always denotes 512-byte blocks and              never 1 Kilobyte blocks, which  is  different              to  the  behaviour  of -ls.  The + and - pre-              fixes signifiy greater than and less than, as              usual,  but  bear  in  mind  that the size is              rounded up to the next unit (so a 1-byte file              is not matched by -size -1M).

参考:http://www.cnblogs.com/wanqieddy/archive/2011/06/09/2076785.html

0 0
原创粉丝点击