简书 Linux 搜索文件夹,find:用于查找符合条件的文件或目录

Linux教程:http://www.fdlly.com/m/linux

本文介绍linux的find命令功能说明、语法、选项与参数、使用详解,并演示如何使用find命令在linux上查找文件或目录

find命令用于用于查找符合条件的文件,它会去保存文件与目录名称的数据库内,查找合乎范本样例条件的文件或目录

find:用于查找符合条件的文件或目录

功能说明:用于查找符合条件的文件或目录

语法:

find [参数] [名称]

选项与参数:

-name filename:查找名为filename的文件

-perm:按执行权限来查找

-user username 按文件属主来查找

-group groupname 按组来查找

-mtim -n +n 按文件更改时间来查找文件,-n指n天以内,+n指n天以前

-atime -n +n 按文件访问时间来查找文件,-n指n天以内,+n指n天以前

-ctime -n +n 按文件创建时间来查找文件,-n指n天以内,+n指n天以前

-nogroup 查无有效属组的文件,即文件的属组在/etc/groups中不存在

-nouser 查无有效属主的文件,即文件的属主在/etc/passwd中不存

-type b/d/c/p/l/f查是块设备、目录、字符设备、管道、符号链接、普通文件

-size n[c] 查长度为n块[或n字节]的文件

-mount 查文件时不跨越文件系统mount点

-follow 如果遇到符号链接文件,就跟踪链接所指的文件

-prune 忽略某个目录

实例

按名字查找

# 在当前目录及子目录中,查找大写字母开头的txt文件

[root@localhost /]# find . -name "[A-Z]*.txt" -print

#在/etc及其子目录中,查找host开头的文件

[root@localhost ~]# find /etc -name "host*" -print

#在$HOME目录及其子目录中,查找所有文件

[root@localhost ~]# find ~ name"*" -print

按权限查找

#在当前目录及子目录中,查找属主具有读写执行,其他具有读执行权限的文件

[root@localhost /]# find . -perm 755 -print

按类型查找

#在当前目录及子目录下,查找符号链接文件

[root@localhost /]# find . -type | -print

按属主及属组

#查找属主是www的文件

[root@localhost /]# find / -user www -type f -print

#查找属主被删除的文件

[root@localhost /]# find / -nouser -type f -print

#查找属组 mysql 的文件

[root@localhost /]# find / -group mysql -type f -print

#查找用户组被删掉的文件

[root@localhost /]# find / -nogroup -type f -print

按时间查找

#查找2天内被更改过的文件

[root@localhost /]# find . -mtime -2 -type f -print

#查找2天前被更改过的文件

[root@localhost /]# find . -mtime +2 -type f -print

#查找一天内被访问的文件

[root@localhost /]# find . -atime -1 -type f -print

#查找一天前被访问的文件

[root@localhost /]# find . -atime +1 -type f -print

#查找一天内状态被改变的文件

[root@localhost /]# find . -ctime -1 -type f -print

#查找一天前状态被改变的文件

[root@localhost /]# find . -ctime +1 -type f -print

#查找10分钟以前状态被改变的文件

[root@localhost /]# find . -cmin +10 -type f -print

按文件新旧

#查找比 aa.txt 新的文件

[root@localhost /]# find . -newer "aa.txt" -type f -print

#查找比 aa.txt 旧的文件

[root@localhost /]# find . ! -newer "aa.txt" -type f -print

#查找比aa.txt新,比bb.txt旧的文件

[root@localhost /]# find . -newer 'aa.txt' ! -newer 'bb.txt' -type f -print

按大小查找

#查找超过1M的文件

[root@localhost /]# find / -size +1M -type f -print

#查找等于6字节的文件

[root@localhost /]# find . -size 6c -print

#查找小于32k的文件

[root@localhost /]# find . -size -32k -print

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值