文件查找:
locate:
      非实时,模糊匹配,查找是根据全系统文件数据库进行的;
# updatedb, 手动生成文件数据库
速度快
 
find:
      实时
      精确
      支持众多查找标准
      遍历指定目录中的所有文件完成查找,速度慢;
      
find 查找路径 查找标准 查找到以后的处理运作
查找路径:默认为当前目录
查找标准:默认为指定路径下的所有文件
处理运作:默认为显示
 
匹配标准:
      -name 'FILENAME':对文件名作精确匹配
            文件名通配:
                  *:任意长度的任意字符
                  ?
                  []
      -iname 'FILENAME': 文件名匹配时不区分大小写
      -regex PATTERN:基于正则表达式进行文件名匹配
      
      -user USERNAME: 根据属主查找
      -group GROUPNAME: 根据属组查找
      
      -uid UID: 根据UID查找
      -gid GID: 根据GID查找
      
      -nouser:查找没有属主的文件
      -nogroup: 查找没有属组的文件
      
      -type
            f: 普通文件
            d
            c
            b
            l
            p
            s
      
      -size [+|-]
            #k
            #M
            #G
/tmp目录,不是目录,并且还不能套接字类型的文件
/tmp/test目录下,属主不是user1,也不是user2的文件;
 
      -mtime  修改时间
      -ctime  
      -atime  访问时间
            [+|-]#
      -mmin
      -cmin
      -amin
            [+|-]#
解释-atime 5 表示距离此刻刚好五天的
    -atime +5  表示距离此刻大于五天都没访问过的
    -atime -5  表示距离此刻五天之内有访问过的
            
      -perm MODE:精确匹配
            /MODE: 任意一位匹配即满足条件
            -MODE: 文件权限能完全包含此MODE时才符合条件
            
            -644
            644: rw-r--r--
            755: rwxr-xr-x
            750: rwxr-x---
      find ./ -perl -001
运作:
      -print: 显示
      -ls:类似ls -l的形式显示每一个文件的详细
      -ok COMMAND {} \; 每一次操作都需要用户确认
      -exec COMMAND {} \;
运作例子:{}表示匹配到的内容
[root@data-1-3 scripts]# find . -amin -30 -exec chmod u-w {} \;
[root@data-1-3 scripts]# ll
total 20
-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh
-r--r--r-- 1 root root   0 Jan  8 08:03 a
-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh
-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh
-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh
-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh
[root@data-1-3 scripts]# find . -amin -30 -ok chmod u+w {} \;
< chmod ... . > ? y
< chmod ... ./a > ? y
[root@data-1-3 scripts]# ll
total 20
-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh
-rw-r--r-- 1 root root   0 Jan  8 08:03 a
-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh
-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh
-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh
-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh
改文件名:
[root@data-1-3 scripts]# find  -perm 644
./a
[root@data-1-3 scripts]# find  -perm 644 -exec mv {} {}.new \;
[root@data-1-3 scripts]# ll
total 20
-rwxr-xr-x 1 root root 280 Jan  7 11:55 1.sh
-rw-r--r-- 1 root root   0 Jan  8 08:03 a.new
-rwxr-xr-x 1 root root 168 Jan  7 11:13 jiou_sum.sh
-rwxr-xr-x 1 root root 261 Jan  8 03:30 sum.sh
-rwxr-xr-x 1 root root 222 Jan  7 17:42 user01.sh
-rwxr-xr-x 1 root root 489 Jan  7 18:24 user.sh
 
再一个例子:将大于1M的文件找出并追加到/tmp/etc.largesfile 
[root@data-1-3 scripts]# find /etc/ -size +1M
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern
[root@data-1-3 scripts]# find /etc/ -size +1M |xargs >> /tmp/etc.largesfile
[root@data-1-3 scripts]# cat /tmp/etc.largesfile
/etc/pki/tls/certs/ca-bundle.trust.crt /etc/selinux/targeted/policy/policy.24 /etc/selinux/targeted/modules/active/policy.kern
[root@data-1-3 scripts]# find /etc/ -size +1M -exec echo {} >> /tmp/etc.largesfile \;                    [root@data-1-3 scripts]# cat /tmp/etc.largesfile
/etc/pki/tls/certs/ca-bundle.trust.crt /etc/selinux/targeted/policy/policy.24 /etc/selinux/targeted/modules/active/policy.kern
/etc/pki/tls/certs/ca-bundle.trust.crt
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern
##############################################################
[root@data-1-3 scripts]# stat a
  File: `a'
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 131939      Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2017-01-08 08:03:12.990058301 +0800
Modify: 2017-01-08 08:03:07.122074618 +0800
Change: 2017-01-08 08:03:12.990058301 +0800
 
[root@data-1-3 scripts]# find -amin -5 -ls
143757    4 drwxr-xr-x   2 root     root         4096 Jan  8 08:03 .
131939    0 -rw-r--r--   1 root     root            0 Jan  8 08:03 ./a
[root@data-1-3 scripts]# find -atime -5 -ls
143757    4 drwxr-xr-x   2 root     root         4096 Jan  8 08:03 .
131939    0 -rw-r--r--   1 root     root            0 Jan  8 08:03 ./a
140442    4 -rwxr-xr-x   1 root     root          168 Jan  7 11:13 ./jiou_sum.sh
140514    4 -rwxr-xr-x   1 root     root          222 Jan  7 17:42 ./user01.sh
140515    4 -rwxr-xr-x   1 root     root          261 Jan  8 03:30 ./sum.sh
140448    4 -rwxr-xr-x   1 root     root          280 Jan  7 11:55 ./1.sh
140513    4 -rwxr-xr-x   1 root     root          489 Jan  7 18:24 ./user.sh

最新文章

  1. python set
  2. 802.1X基础
  3. 常用的logging配置
  4. 通过python将图片生成字符画
  5. 马旭飞:共探H3 BPM社区发展战略
  6. mysql及redis环境部署时遇到的问题解决
  7. python 的 class
  8. .NET基础之:i++和i=i+1和++i的区别
  9. 关于aspx 页面生成html 源码顶部空行不得不说的事儿
  10. Ngui _CD技能特效
  11. js音乐播放器
  12. PHP cookie禁用时session 方案
  13. 块级元素行内元素以及display属性
  14. [shiro学习笔记]第四节 使用源代码生成Shiro的CHM格式的API文档
  15. mysql执行sql脚本文件
  16. Hibernate配置文件的书写
  17. MYSQLi数据访问查询数据
  18. XiaoKL学Python(E)Generator Expressions
  19. 【翻译】What is State Machine Diagram(什么是状态机图)?
  20. Mongo如何导出 CSV文件

热门文章

  1. 细说Redis持久化机制
  2. 自定义PropertyGrid控件【转】
  3. Linux以下基于TCP多线程聊天室(server)
  4. persits.jpeg 水印组件
  5. C语言变长数组 struct中char data[0]的用法
  6. Lightoj 1088 - Points in Segments 【二分】
  7. website link
  8. 基于HTML,css,jQuery,JavaScript,MySQL搭建博客系统
  9. JavaScript删除确认框
  10. Create an OData v4 Endpoint Using ASP.NET Web API 2.2(使用ASP.NET Web API 2.2创建OData v4端点)