[CentOS 7系列]文件搜索

前端之家收集整理的这篇文章主要介绍了[CentOS 7系列]文件搜索前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在linux中,当我们需要搜索需要的文件时,可以使用which命令,也可以适用whereis,还可以使用locate工具,但更常用的是find命令。find命令是一个用来搜索符合特定条件的文件的命令工具。下面将介绍几种find命令的用法

1、按名称筛选

  1. [root@server02~]#find/-name"test1*"
  2. /root/test1
  3. /root/test12
  4. /tmp/test1.txt
  5. /tmp/test12.txt
  6. /tmp/test123.txt

2、按类型筛选

  1. [root@server02~]#find/-typed-name"test1*"//d表示目录
  2. /root/test1
  3. /root/test12

3、按大小筛选

  1. [root@server02~]#ls-lh/tmp|grep"test1"
  2. -rw-r--r--.1rootroot1.2K53009:09test123.txt
  3. -rw-r--r--.1rootroot7.8K53009:08test12.txt
  4. -rw-r--r--.1rootroot3.6M53009:12test1.txt
  5. [root@server02~]#find/tmp-size-5k-name"test1*"//小于5K
  6. /tmp/test123.txt
  7. [root@server02~]#find/tmp-size+1M-name"test1*"//大于1M
  8. /tmp/test1.txt

4、按时间筛选

通过stat命令能查看文件的atime(access time)、mtime(modify time)、ctime(change time)等文件信息。

  1. [root@server02~]#stat/tmp/test1.txt
  2. File:'/tmp/test1.txt'
  3. Size:3689322 Blocks:7208IOBlock:4096regularfile
  4. Device:803h/2051d Inode:16958226Links:1
  5. Access:(0644/-rw-r--r--)Uid:(0/root)Gid:(0/root)
  6. Context:unconfined_u:object_r:user_tmp_t:s0
  7. Access:2017-05-3009:11:39.189757015+0800
  8. Modify:2017-05-3009:12:07.369705343+0800
  9. Change:2017-05-3009:12:07.369705343+0800
  10. Birth:-

通过atime、mtime、ctime筛选的最小单位为“天”。而通过mmin、cmin、amin筛选的最小单位为“分钟”。

  1. [root@server02~]#find/tmp-atime-1-name"test"//atime在1天以内的
  2. /tmp/test
  3. /tmp/test/test
  4. [root@server02~]#find/tmp-atime+1-name"test"//atime在1天之前的
  5. [root@server02~]#
  6. [root@server02~]#touch/tmp/test
  7. [root@server02~]#find/tmp-amin+10-name"test"//atime在10分钟前的
  8. /tmp/test/test

5、按inode筛选

  1. [root@server02tmp]#ll-i
  2. total4136
  3. 16777289-rw-r--r--.2rootroot0May3008:501-hd.txt
  4. 16777289-rw-r--r--.2rootroot0May3008:501.txt
  5. 33595402drwxr-xr-x.3rootroot18May3009:24test
  6. 16958225lrwxrwxrwx.1rootroot4May3008:43test-ln->test
  7. 16958226-rw-r--r--.1rootroot3689322May3009:12test1.txt
  8. 16958227-rw-r--r--.1rootroot7917May3009:08test12.txt
  9. 16958228-rw-r--r--.1rootroot1131May3009:09test123.txt
  10. 16958239-rw-r--r--.2rootroot263523May3009:11txt
  11. 16958239-rw-r--r--.2rootroot263523May3009:11txt_hd
  12. [root@server02tmp]#find/tmp-inum16777289
  13. /tmp/1.txt
  14. /tmp/1-hd.txt
  15. [root@server02tmp]#find/tmp-inum16958239
  16. /tmp/txt
  17. /tmp/txt_hd


以上5种筛选方式同时使用时是同时满足的关系。表示筛选出来的文件要符合多个条件。如果多个条件中只需要符合其中任意一个,可以使用“-o”参数。

  1. [root@server02tmp]#find/tmp-amin+15-name"test"
  2. /tmp/test/test
  3. [root@server02tmp]#find/tmp-amin+15-o-name"test"
  4. /tmp/.font-unix
  5. /tmp/.X11-unix
  6. /tmp/.ICE-unix
  7. /tmp/.Test-unix
  8. /tmp/.XIM-unix
  9. /tmp/test
  10. /tmp/test/test
  11. ......

猜你在找的CentOS相关文章