find 命令

  •  查找root目录下面以cfg结尾的文件

[root@localhost ~]# find /root/ -name '*cfg'

/root/anaconda-ks.cfg

/root/xuefei/e_file.cfg

/root/file.cfg

[root@localhost ~]# ll

drwxr-xr-x. 3 root root   21 1月  30 09:02 2018

-rw-------. 1 root root 1421 1月  22 17:16 anaconda-ks.cfg

-rw-------. 1 root root 1421 1月  30 09:06 file.cfg

drwxr-xr-x. 3 root root   67 2月   4 08:44 xuefei

  •  查找root目录下面以cfg结尾的文件(忽略cfg大小写)

[root@localhost ~]# find /root/ -iname '*cfg'

/root/anaconda-ks.cfg

/root/xuefei/e_file.cfg

/root/file.cfg

/root/file.Cfg

[root@localhost ~]# find /root/ -name '*cfg'

/root/anaconda-ks.cfg

/root/xuefei/e_file.cfg

/root/file.cfg

[root@localhost ~]# ll

drwxr-xr-x.   3 root root   21 1月  30 09:02 2018

-rw-------. 1 root root 1421 1月  22 17:16 anaconda-ks.cfg

-rw-------. 1 root root 1421 1月  30 09:06 file.cfg

-rw-------. 1 root root 1421 2月   4 08:49 file.Cfg

drwxr-xr-x.   3 root root   67 2月   4 08:44 xuefei

  •  查找root目录下面不以cfg结尾的文件(否定参数)

[root@localhost ~]# find /root/ ! -name "*cfg"

/root/

/root/.bash_logout

/root/xuefei/2018

/root/xuefei/2018/01

/root/xuefei/2018/01/29

/root/xuefei/2018/01/29/chmod_022.test

  •  查找root目录下面文件(按照类型查找)

说明:普通文件    符号连接    d 目录    字符设备    块设备    套接字    Fifo

[root@localhost ~]# find /root/ -type d 

/root/

/root/.ssh

/root/xuefei

/root/xuefei/2018

/root/xuefei/2018/01

/root/xuefei/2018/01/29

  •  查找root目录下面文件(最大深度为2)

说明:最大深度:-maxdepth    最小深度:-mindepth

[root@localhost ~]# find /root/ -maxdepth 2 -type d

/root/

/root/.ssh

/root/xuefei

/root/xuefei/2018

[root@localhost ~]# find /root/ -type d

/root/

/root/.ssh

/root/xuefei

/root/xuefei/2018

/root/xuefei/2018/01

/root/xuefei/2018/01/29

  •  查找root目录修改时间在1天以内

访问时间(-atime/天,  -amin/分钟):用户最近一次访问时间

修改时间(-mtime/天,-mmin/分钟):文件最后一次修改时间

变化时间(-ctime/天,  -cmin/分钟):文件数据元(例如权限等)最后一次修改时间

[root@localhost ~]# find /root/ -mtime -1

/root/

/root/xuefei

/root/xuefei/e_file.cfg

/root/file.Cfg

[root@localhost ~]# ll /root/xuefei/e_file.cfg

-rw-------. 1 root root 1421 2月   4 08:44 /root/xuefei/e_file.cfg

  •  查找root目录下10KB以内的文件

说明:b - 块(512字节)    c - 字节    w - 字(2字节)    k  千字节    M - 兆字节    G - 吉字节

[root@localhost ~]# find /root/ -size -10k

/root/

/root/.bash_logout

/root/.bash_profile

/root/.bashrc

/root/.cshrc

/root/.tcshrc

/root/anaconda-ks.cfg

/root/.bash_history

/root/.ssh

/root/.ssh/authorized_keys

/root/file.cfg

/root/.lesshst

/root/file.Cfg

[root@localhost ~]# ll

drwxr-xr-x. 3 root root   21 1月  30 09:02 2018

-rw-------. 1 root root 1421 1月  22 17:16 anaconda-ks.cfg

-rw-------. 1 root root 1421 1月  30 09:06 file.cfg

-rw-------. 1 root root 1421 2月   4 08:49 file.Cfg

  •  查找root目录下所有长度为零的文件

[root@localhost ~]# find /root/ -empty

/root/xuefei/2018/01/29/chmod_022.test

/root/xuefei/cp.sh

/root/xuefei/chmod.text

/root/2018/mv_test/cp.sh

/root/2018/mv_test/xuefei/2018/01/29

/root/2018/mv_test/xuefei/cp.sh

[root@localhost ~]# ll /root/xuefei/2018/01/29/chmod_022.test

-rw-r--r--. 1 root root 0 2月   1 08:17 /root/xuefei/2018/01/29/chmod_022.test

[root@localhost ~]# cat /root/xuefei/2018/01/29/chmod_022.test

  • 借助-exec选项与其他命令结合使用

[root@localhost ~]# find /root/ -empty -exec ls -l  {}  \;

-rw-r--r--. 1 root root 0 2月   1 08:17 /root/xuefei/2018/01/29/chmod_022.test

-rw-r--r--. 1 root root 0 1月   30 08:37 /root/xuefei/cp.sh

-rwxr--r--. 1 root root 0 2月   1 07:52 /root/xuefei/chmod.text

-rw-r--r--. 1 root root 0 1月   30 08:36 /root/2018/mv_test/cp.sh

-rw-r--r--. 1 root root 0 1月   30 08:45 /root/2018/mv_test/xuefei/cp.sh

  •  查找root目录下所有长度为零的文件

[root@localhost ~]# find /root/ -type f -perm 777

/root/file.Cfg

[root@localhost ~]# ll

drwxr-xr-x.   3 root root   21 1月    30 09:02 2018

-rw-------. 1 root root 1421 1月   22 17:16 anaconda-ks.cfg

-rw-------. 1 root root 1421 1月   30 09:06 file.cfg

-rwxrwxrwx.  1 root root 1421 2月   4 08:49 file.Cfg

drwxr-xr-x.   3 root root   67 2月   4 08:44 xuefei

转载于:https://my.oschina.net/u/3771523/blog/1618318

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值