find命令总结

find命令根据用户提供的条件查找文件。

~ 表示$HOME目录

 表示当前目录

 / 表示根目录 

指定查找类型

`-type` 是一个用于指定文件类型的选项,它可以用于在 `find` 命令中查找特定类型的文件。

1. `-type f`:只查找普通文件,不包括目录、设备文件等。

2. `-type d`:只查找目录,不包括普通文件、设备文件等。

3. `-type l`:只查找符号链接文件。

4. `-type b`:只查找块设备文件。

5. `-type c`:只查找字符设备文件。

6. `-type p`:只查找命名管道(FIFO)。

7. `-type s`:只查找套接字。

除了使用单个 `-type` 选项来指定文件类型之外,还可以使用 `-not -type` 或 `-not -xtype` 来排除某些类型的文件。例如,要查找除符号链接之外的所有文件,可以使用以下命令:find /path/to/search -not -type l

根据名字查找文件

/ 代表从根目录查找  

-name 代表查找名字

[root@nginx140 ~]#  find / -name 'SNMPv2-TM.txt' 
/usr/share/snmp/mibs/SNMPv2-TM.txt

根据名字范围查找文件

[A-Z]*.txt 代表查找查找的文件以A到Z开头的txt文件

[root@nginx140 ~]# find / -name '[A-Z]*.txt' -print
/usr/lib/python3.9/site-packages/python_dateutil-2.8.1-py3.9.egg-info/SOURCES.txt
/usr/lib64/python3.9/lib2to3/Grammar.txt
/usr/lib64/python3.9/lib2to3/PatternGrammar.txt
/usr/lib64/python3.9/LICENSE.txt

指定具体的目录查找文件

指定 /etc 目录下面 以host开头的文件

[root@nginx140 ~]# find /etc -name 'host*' -print 
/etc/host.conf
/etc/hosts
/etc/hostname

按执行权限来查找

-perm 

`-type f`表示只查找文件

[root@nginx140 ~]# find /opt -type f -perm 644 -print
/opt/nginx.conf

按属主查找文件

-user root 就是查找属主为root

[root@nginx140 ~]# find /opt -type f -user root -print
/opt/nginx.conf

按照属组查找文件

[root@nginx140 ~]# find /opt -type f -group root -print
/opt/nginx.conf

根据时间查找更改过的文件

-mtime -10 代表查找10天以内修改过的

[root@nginx140 ~]# find /root/ -mtime -10  -print
/root/
/root/.bash_history
/root/.viminfo

查找在根目录下过去一天修改过的文件

find / -type f -mtime -1 -print

查找一天以前需改过的文件

-mtime +1 代表一天以前

 find / -type f -mtime +1 -print

根据时间查找访问过的文件

-atime    -n +n 

find /root/  'type  -f' -atime  -10 

根据创建时间来查找文件

[root@nginx140 ~]# find /root/ -type f -ctime -10
/root/.bash_history
/root/.viminfo

根据大小查找文件

-size + 100M 就是大于100MB的文件

-size -100M 就是小于100MB的文件 

查找大于100MB的文件

[root@nginx140 ~]#  find / -size +100M -type f -print

查找小于100字节的文件

find . -size -100c -print

查找等于10kb的文件

[root@nginx140 ~]# find . -size 10k -print
./nginx-1.20.2/src/core/ngx_log.h
./nginx-1.20.2/src/core/ngx_rbtree.c
./nginx-1.20.2/src/core/ngx_regex.c
./nginx-1.20.2/src/core/ngx_sha1.c
./nginx-1.20.2/src/core/ngx_syslog.c
./nginx-1.20.2/src/http/ngx_http_copy_filter_module.c
./nginx-1.20.2/src/os/unix/ngx_freebsd_sendfile_chain.c
./nginx-1.20.2/src/stream/ngx_stream.h
./nginx-1.20.2/src/stream/ngx_stream_handler.c
./nginx-1.20.2/src/stream/ngx_stream_realip_module.c
./nginx-1.20.2/objs/src/core/ngx_murmurhash.o
./nginx-1.20.2/objs/src/os/unix/ngx_dlopen.o

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值