find命令及

1.查找命令
which 通过PATH环境变量查找可执行文件
whereis 通过文件环境变量查找,比whic范围大一些
locate 通过索引数据库查找文件,centos7下要安装mlocate
find 通过直接搜索硬盘查找,功能强大

参数 作用
-name: 按照名字查找
-perm: 安装权限查找
-prune: 不再当前指定的目录下查找
-user: 文件属主来查找
-nogroup: 文件所属组来查找
-nouser: 查找无有效所属组的文件
-type: 按照文件类型查找

按时间查找
-atime n :将 n24 小时内存取过的的文件列出来
-ctime n :将 n
24 小时内改变、新增的文件或者目录列出来
-mtime n :将 n*24 小时内修改过的文件或者目录列出来

按名称查找

[root@localhost ~]# find /etc/ -name 'audit*'
/etc/systemd/system/multi-user.target.wants/auditd.service
/etc/selinux/targeted/active/modules/100/auditadm
/etc/audit
/etc/audit/audit-stop.rules
/etc/audit/auditd.conf
/etc/audit/rules.d/audit.rules
/etc/audit/audit.rules

根据文件从属关系查找
find . -user root 查找属主指定用户的所有文件

[root@localhost ~]# find . -user root
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history

find . -group root 查找属组指定用户的所有文件

[root@localhost ~]# find . -group root
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history

find . -uid 0 查找属主指定的UID的所有文件

[root@localhost ~]# find . -uid 0
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history

find . -gid 0 查找属组指定的UID的所有文件

[root@localhost ~]# find . -gid 0
.
./.bash_logout
./.bash_profile
./.bashrc
./.cshrc
./.tcshrc
./anaconda-ks.cfg
./.bash_history

根据文件类型查找

类型 作用
f 普通文件
d 目录文件
l 符号链接文件
b 块设备文件
c 字符设备文件
p 管道文件
s 套接字文件

find . -type f 查找当前目录的普通文件

[root@localhost home]# find . -type f
./cmd/.bash_logout
./cmd/.bash_profile
./cmd/.bashrc
./qaz/.bash_logout
./qaz/.bash_profile
./qaz/.bashrc

find . -type d 查找当前目录下的目录文件

[root@localhost home]# find . -type d
.
./cmd
./qaz
./jack
./zhuzhu
./maomao100

根据文件的大小查找(常用的单位k,m,G)

猜你喜欢

转载自blog.csdn.net/weixin_43150761/article/details/83024779