find命令使用

1 find . -type d:查找当前目录下的目录(.代表当前目录,d代表目录,若是f则代表文件)
2 find . -name ‘‘a1.txt’’:精确匹配当前目录名字为a1.txt的文件(注意,如果文件名包含!等shell里的变量名,就必须使用单引号)
find . -name " *a1* ":(模糊查找)查找名字中带有a1的文件或目录
find . -name " *a1 ":(模糊查找)查找名字以a1结尾的文件或目录
find . -name " a1* ":(模糊查找)查找名字以a1开头的文件/目录
3find . -regex .*.txt:查找名字符合正则表达式的文件/目录,注意前面的.*(这在正则表达式中表示任意多个字符)

find命令执行模式:

例一:
find . -type d -print -exec ls {} ;:找到当前文件下的所有文件/目录及文件/目录的级联文件/目录
这句话的执行顺序是,先查找本目录的目录/文件,然后执行-exec ls {} \命令,这个命令的执行原理是先对当前目录执行ls然后输出,再对该目录下的所有目录执行ls,注意ls 和{} 以及\之间必须有空格,最后还必须加;
举例如下:
[root@oracle test]# ll
total 8
-rw-r–r–. 1 root root 0 Sep 24 16:17 1
-rw-r–r–. 1 root root 45 Sep 24 15:57 1.txt
-rw-r–r–. 1 root root 9 Sep 24 15:58 2.txt
-rw-r–r–. 1 root root 0 Sep 24 15:59 3.txt
-rw-r–r–. 1 root root 0 Sep 24 16:17 abc1
drwxr-xr-x. 2 root root 21 Sep 24 17:35 test1
drwxr-xr-x. 2 root root 6 Sep 24 16:00 test2
drwxr-xr-x. 2 root root 6 Sep 24 16:00 test3

[root@oracle test]# find . -type d -print -exec ls {} ;
.
1 1.txt 2.txt 3.txt abc1 test1 test2 test3
./test2
./test1
test1.1
./test3
例二:
find . -name abc1 -exec rm -rf {} ;找到当前目录下名为abc1的文件 并执行删除
[root@oracle test]# ll
total 8
-rw-r–r–. 1 root root 0 Sep 24 16:17 1
-rw-r–r–. 1 root root 45 Sep 24 15:57 1.txt
-rw-r–r–. 1 root root 9 Sep 24 15:58 2.txt
-rw-r–r–. 1 root root 0 Sep 24 15:59 3.txt
drwxr-xr-x. 2 root root 21 Sep 24 17:35 test1
drwxr-xr-x. 2 root root 6 Sep 24 16:00 test2
drwxr-xr-x. 2 root root 6 Sep 24 16:00 test3

我目前并不觉得这有什么用,直接列出来或删除不香吗;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值