2023年7月26日发(作者:)
find-exec命令总是报缺参数错误前⾔:最近⼏天使⽤find的⾼级功能,但执⾏到 -exec命令的时候总是提⽰错误信息如下:“find: missing argument to `-ok' ”,花了点时间,研究了下帮助(man),终于是搞清楚了。说明:find命令,配合-exec参数,可以对查询的⽂件进⾏进⼀步的操作,可以得到很多有⽤的功能,⽐如说⽂件包含特定字符串的查询等,要了解这个功能,最简单直接的就是看find命令帮助,列出 -exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments tothe command until an argument consisting of #;' is encountered. The string {}' is replaced by the current file name beingprocessed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in someversions of find. Both of these constructions might need to be escaped (with a ') or quoted to protect them from
expansion by the shell. The command is executed in the starting directory.其实只要读懂这段话就理解了废话少说,这⾥简单说明⼀下-exec 参数后⾯跟的是 command命令,注意点如下:command命令的终⽌,使⽤ ';' (分号)来判定,在后⾯必须有⼀个 ';''{}',使⽤{}来表⽰⽂件名,也就是find前⾯处理过程中过滤出来的⽂件,⽤于command命令进⾏处理特别强调,对于不同的系统,直接使⽤分号可能会有不同的意义, 使⽤转义符 ''在分号前明确说明,对于前⾯我们遇到的问题,主要就是这个原因引起的!举例:1.查询所有保护字符串“Hello”的⽂件find / -exec grep "Hello" {} ;2.删除所有临时⽂件find / -name "*.tmp" -exec rm -f {} ;
发布者:admin,转转请注明出处:http://www.yc00.com/web/1690361283a337819.html
评论列表(0条)