每天一个Linux命令(08):find之exec

通常,查找到文件之后,还会有后续的操作,使用exec可以实现。

示例1、查找到后ll查看一下

find . -type f -exec ls -l {} ;
前面都懂,exec后面带的是执行的命令,{}指exec前查找到的文件,最后以;结尾,\是转义的作用,防止;出现歧义。

示例2、查找到后rm删除

find . -ctime -2 -exec rm -r {} ;

[root@localhost ppp]# ll
total 4
-rw-r--r--. 1 root root 0 Mar 30 13:45 1.doc
-rw-r--r--. 1 root root 0 Mar 30 13:45 1.sh
-rw-r--r--. 1 root root 7 Mar 30 13:46 1.txt
[root@localhost ppp]# find . -name 1.doc -exec rm -i {} \;
rm: remove regular empty file './1.doc'? y
[root@localhost ppp]# ll
total 4
-rw-r--r--. 1 root root 0 Mar 30 13:45 1.sh
-rw-r--r--. 1 root root 7 Mar 30 13:46 1.txt

-exec后可以跟任何命令,可以尝试练习,比如cp mv等等常用命令

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

空城雀

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值