日期:2014-05-16  浏览次数:20650 次

Linux__Command__find
源文:http://blog.csdn.net/windone0109/archive/2008/08/23/2817792.aspx

find命令,居家必备,新手必学。多用参数不知道会不会快点呢,貌似没什么感觉
linux 查找目录或文件 

查找目录:find /(查找范围) -name '查找关键字' -type d
查找文件:find /(查找范围) -name 查找关键字 -print

如果需要更进一步的了解,可以参看Linux的命令详解。
这里摘抄如下:

·find path -option [ -print ] [ -exec -ok command ] {} \;
#-print 将查找到的文件输出到标准输出
#-exec command {} \;     -----将查到的文件执行command操作,{} 和 \;之间有空格
#-ok 和-exec相同,只不过在操作前要询用户

====================================================

-name filename              #查找名为filename的文件
-perm                       #按执行权限来查找
-user   username            #按文件属主来查找
-group groupname            #按组来查找
-mtime -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime   -n +n              #按文件访问时间来查
-perm                       #按执行权限来查找
-user   username            #按文件属主来查找
-group groupname            #按组来查找
-mtime -n +n                #按文件更改时间来查找文件,-n指n天以内,+n指n天以前
-atime   -n +n              #按文件访问时间来查找文件,-n指n天以内,+n指n天以前 
-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]*" -pri26nbsp;   #对匹配的文件使用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 +10 -print              #查长度超过期作废10块的文件(1块=512字节)

$cd /
$find etc home apps   -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name "passwd*" -exec grep "cnscn" {} \; #看是否存在cnscn用户
$find . -name "yao*" | xargs file
$find . -name "yao*" | xargs echo   "" > /tmp/core.log
$find . -name "yao*" | xargs chmod o-w

======================================================

find -name april*                      在当前目录下查找以april开始的文件
find -name april* fprint file        在当前目录下查找以april开始的文件,并把结果输出到file中
find -name ap* -o -name may* 查找以ap或may开头的文件
find /mnt -name tom.txt -ftype vfat 在/mnt下查找名称为tom.txt且文件系统类型为vfat的文件
find /mnt -name t.txt ! -ftype vfat   在/mnt下查找名称为tom.txt且文件系统类型不为vfat的文件
find /tmp -name wa* -type l           在/tmp下查找名为wa开头且类型为符号链接的文件
find /home -mtime -2                 在/home下查最近两天内改动过的文件
find /home   -atime -1                  查1天之内被存取过的文件
fin