文件查找 locate和find

1400阅读 0评论2015-05-18 流云863
分类:LINUX

文本查找:grepegrepfgrep

文件查找:locatefind

locate:

非实时查找,是根据全系统文件数据库进行的,updatedb:手动生成数据库

每天晚上更新数据库

速度快

find

实时,

精确

支持众多查找标准

遍历指定目录中的所有文件完成查找,速度慢

查找路径:默认当前目录

查找标准:默认为制定命令下的所有文件

处理动作:默认为显示

 

匹配标准:

-name filename 对文件名精确匹配

    *

    ?

    [ ]

 

-iname          忽略大小写

-regex     基于正则表达式

-uid

-gid

-user

-group

-nouser   查找没有用户名的文件,

-nogroup

-type

普通文件

目录文件

字符

b  block

l  link

管道文件

套接字文件

-size  [+\-]

#k(小写)  +10k

#M

#G

组合条件

-a

-o

-not

时间戳        [+\-]

-mtime      天        -mmin              分

-ctime                    -cmin

-atime                    -amin

权限           -perm

MODE          精确匹配   

/MODE                 任一匹配                               eg.   /700匹配到755

-MODE         包含匹配              eg.  -311可以匹配到755

eg.

find /etc/ -perm  -733

执行/处理

-print           打印

-ls              显示类似与 ls -l

-ok   COMMEND    咨询是否执行   

-exec COMMEND    执行

mv

chmod

echo

。。
xargs  从标准输入中简历与执行命令行   相当于 -exec
eg.
find /etc -size +1M |xargs echo {} >> /tmp/d

eg.

 root@localhost t e s t ] # find . / -type d -ok chmod + X 


(1)[root@localhost ~]# find /var -user root -a -group mail

(2)[root@localhost ~]# find /usr -not -user root -a -not -user bin -a -not -user student

(3)[root@localhost ~]# find /etc -mtime -7 -not \( -user root -o -user student \)

(4)find / \( -nouser -o -nogroup \) -a -atime -1 -exec chown root:root {} \;

(5)[root@localhost ~]# find /etc/ -size +1M >> /tmp/etc.largefile

(6)[root@localhost tmp]# find /etc/ -not -perm /222 -ls

上一篇:强大的vim编辑器
下一篇:没有了