Linux笔记(17)find命令

find命令
用途:用于查找文件或目录
格式:find[查找范围][查找条件][动作]
1.精确查找:必须完全一样 locate
2.模糊查找:可以包含一部分字符串 find

特殊查找条件
-o:逻辑或,只要所给的条件中有一个满足,寻找条件就算满足
-not:逻辑非,在命令中可用“!”表示。该运算符表示查找不满足所给条件的文件

查找动作:
-exec:将find查找的结果交给-exec后面的命令执行
-OK:比-exec动作多一个确认

 [root@localhost lianxi]$ find /lianxi -name ddd.txt -type f -ok rm -rf {} \;

常用查找条件:
1.-name:按文件名称查找

         [root@localhost lianxi]$ find -name "chen*"
         ./chen3
         ./chen4
         ./chen5
		 ./chen6
	     ./chen7
		 ./chen8
		 ./chen9


2.-inname:按文件名称查找,不区分大小写

            [root@localhost lianxi]$ touch D.txt
			[root@localhost lianxi]$ touch d.txt
			[root@localhost lianxi]$ find -iname d.txt
			./D.txt
			./d.txt
			[root@localhost lianxi]$ 


3.-size:按文件大小查找

[root@localhost lianxi]#  find /boot -size +1M/boot/grub2/fonts/unicode.pf2
/boot/System.map-3.10.0-1160.el7.x86_64
/boot/vmlinuz-3.10.0-1160.el7.x86_64
/boot/initramfs-0-rescue-f505240a86b946f48842269351c8fa9f.img
/boot/vmlinuz-0-rescue-f505240a86b946f48842269351c8fa9f
/boot/initramfs-3.10.0-1160.el7.x86_64.img
/boot/initramfs-3.10.0-1160.el7.x86_64kdump.img
[root@localhost lianxi]# 

4.-type:按文件类型查找
f --》普通文件file
d --》目录 directory
l --》链接文件 link
c --》字符设备文件 character --》显示字符相关
b --》块设备文件block --》磁盘设备文件
p --》管道文件 pipe
s --》socket文件

5.-mtime:按文件更改时间查找
格式:find /usr -mtime +/-数字
数字:数字前面有+,大于数字的天数,数字前面有-,小于数字的天数,没有+或-,等于数字的天数
mtime -->modify time 修改时间,改动了文件里的内容
ctime -->change time 访问时间,修改文件的属性
atime -->assess time 访问时间,只要看一下文件里的内容

[root@localhost lianxi]# stat d.txt
文件:"d.txt"
大小:0         	块:0          IO 块:4096   普通空文件
设备:fd00h/64768d	Inode:51275660    硬链接:1
权限:(0644/-rw-r--r--)  Uid:(    0/    root)   Gid:(    0/    root)
环境:unconfined_u:object_r:admin_home_t:s0
最近访问:2022-03-06 15:33:17.353958944 +0800
最近更改:2022-03-06 15:33:17.353958944 +0800
最近改动:2022-03-06 15:33:17.353958944 +0800
创建时间:-
[root@localhost lianxi]# 

      

6.-newer:按比某个文件更新的查找

[root@localhost lianxi]# find . -newer aa
./aa/bb
./aa/bb/cc
./aa/bb/cc/dd
./aa/bb/cc/dd/hello
./aa/bb/cc/hello
./aa/bb/hello
[root@localhost lianxi]# 

7.-maxdepth,查找文件的时候,目录的深度
1代表当前
2代表下一级目录
3下一级的下一级目录,一次类推

[root@localhost lianxi]# find . -maxdepth 2 -name hello
./aa/hello
./hello

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值