码迷,mamicode.com
首页 > 系统相关 > 详细

Linux文件查找--location find 命令

时间:2015-06-29 13:00:13      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

文件查找
grep egrep fgrep 文本查找

文件查找:
locate:
非实时,模糊匹配,查找是根据全系统文件数据库进行的;
# 手动生成文件数据库 updatedb;

find:
实时查找,精确, 速度慢
遍历指定目录中的所有的文件完成查找;
支持众多查找标准

find 查找路径 查找标准 查找到以后的处理运作
查找路径:默认为当前目录
查找标准:默认为指定路径下的所有文件
处理运作:默认为显示 打印

匹配标准:
-name ‘FILENAME‘: 对文件名进行精确查找
文件名通配:
*: 任意长度的任意字符
?:
[]:
-iname ‘FILENAME‘: 文件名匹配时不区分大小写
-regex PATTERN: 基于正则表达式进行查找
-user USERNAEM:
-group GROUPNAME:
-uid UID
-gid GID 用户被删后,属组gid号
-nouser: 查找没有属组的文件
-type
f: 普通文件
d:
c:
b:
l:
p:
s:
-size
+- #k
#M
#G
组合条件
-a 且
-o 或
-not 非
find /tmp -not -type -d

-mtime
-ctime
-atime + 5 -
[+|-]5 ----------|-----------> now

-mmin
-cmin
-amin
[+|-]# 分钟

-perm:
MODE 依据权限精确查找
-MODE: 每一位权限都要匹配才行 包含关系:文件全乡能完全包含MODE时才能显示
/MODE: 九位权限有一位匹配就行

运作:
-print:显示
-ls:类似类ls -l的形式显示每一个文件的详细信息
-ok:COMMOND \; 每次操作都需要确认
-exec COMMAD \; 不需要确认
find ./ -perm -006 -exec chmod o-w {} \;
find ./ -type d -ok chmod +x {} \;
find ./ -perm -020 -exec mv {} {}.new \;
find ./ -name "*.sh" -a -perm -111 -exec chmod o-x {} \;

find /etc -sixe +1M -exec echo {} >> /tmp/etc.largefiles \;
find /etc -size +1M | xargs echo >> /tmp/etc.largefiles

练习:

1、查找/var目录下属主为root且属组为mial的文件
find /var -user root -group mail

2、查找/usr目录下不属于root,bin 或student的文件
find /usr -not -user root -a -not -user bin -a -not -user student
find /usr -not \( -user root -o -user bin -o -user student \)

3、查找/etc目录下最近一周修改过且不属于root和student用户的文件;
find /etc -mtime -7 -a -not -user root -a -not -user student

4、查找当前系统上没有属主或属主且最近一天内曾被访问的文件,并将其属主和属组都修改为root
find / (\ -nouser -o -nogroup \) -a -atime -1 -exec chown root:root {} \;

5、查找\etc目录下大于1M的文件,并且将其文件名写入/tmp/etc.largefiles文件中;
find /etc -sixe +1M -exec echo {} >> /tmp/etc.largefiles \;
find /etc -size +1M | xargs echo >> /tmp/etc.largefiles

6、查找/etc目录下所有用户都没有写权限的文件,显示出其详细信息
find /etc -not -perm /222 -ls

Linux文件查找--location find 命令

标签:

原文地址:http://www.cnblogs.com/chrisDuan/p/4607070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!