find命令find: missing argument to解决方法

find搜索姿势

默认先处理文件夹,再处理文件夹
find [选项] [路径] [查找条件] [处理动作]

find后接命令

find命令强大之处在于

  • 可以在查找到内容后,调用命令对查找到的内容进行进一步的处理

查看find帮助文件

  • [处理动作]相关内容
actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print 
      -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
      -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
      -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

按照帮助文件执行报错

[root@C6-56 ~]# find ./ -name 'Video*' -exec rm -rf {}
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name 'Video*' -exec rm -rf {} ;
find: missing argument to `-exec'

正确find加命令处理姿势

find -name "*.sh" -ok mv {} /opt \; 问一次移一次
find -name "*.sh" -exec mv {} /opt \;不问直接移

{}花括号相当于find内置变量,代表前边find查找到的结果
一旦有-ok 或者有 -exec 后边就必须有 ;结束,这个是语法要求

实例1:查找当前目录下所有zip文件并删除

[root@C6-56 ~]# find ./ -name '*.zip'
./Videos.tar.zip
[root@C6-56 ~]# find ./ -name '*.zip' -exec rm {}
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name '*.zip' -exec rm{}
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name '*.zip' -exec rm {}
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name '*.zip' -exec rm {} \;
[root@C6-56 ~]# find ./ -name '*.zip'

实例2:查找当前目录下包含123的文件和文件夹并删除

[root@C6-56 ~]# ll 123*
-rw-r--r--. 1 root root   81 Apr  8 13:03 123.txt
-rw-r--r--. 1 root root   53 Apr  8 09:10 123.txt.bak

123:
total 8
-rw-r--r--. 1 root root    7 Apr  8 07:09 123.txt
drwxr-xr-x. 3 root root 4096 Apr  8 07:09 321
[root@C6-56 ~]# find ./ -name '123*'
./123.txt.bak
./123
./123/123.txt
./123/321/123
./123/321/123/123.txt
./123/321/123.txt
./123.txt
[root@C6-56 ~]# find ./ -name '123*' -exec rm -rf {}
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name '123*'
./123.txt.bak
./123
./123/123.txt
./123/321/123
./123/321/123/123.txt
./123/321/123.txt
./123.txt
[root@C6-56 ~]# find ./ -name '123*' -exec rm -rf {} ;
find: missing argument to `-exec'
[root@C6-56 ~]# find ./ -name '123*'
./123.txt.bak
./123
./123/123.txt
./123/321/123
./123/321/123/123.txt
./123/321/123.txt
./123.txt
[root@C6-56 ~]# find ./ -name '123*' -exec rm -rf {} \;
find: `./123': No such file or directory
[root@C6-56 ~]# find ./ -name '123*'
[root@C6-56 ~]# 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值