find命令应用exec及xargs
find最普通的用法是查找文件,然后要对文件进行处理就需要用到参数-exec。
先看下manpage中介绍:
- -exec command ;
- Execute command; true if status is returned. All following arguments to find are taken to
- be arguments to the command until an argument consisting of `;' is encountered. The string
- `{}' is replaced by the current file name being processed everywhere it occurs in the argu‐
- ments to the command, not just in arguments where it is alone, as in some versions of find.
- Both of these constructions might need to be escaped (with a `\') or quoted to protect them
- from expansion by the shell. See the EXAMPLES section for examples of the use of the -exec
- option. The specified command is run once for each matched file. The command is executed in
- the starting directory. There are unavoidable security problems surrounding use of the
- -exec action; you should use the -execdir option instead.
-exec 参数后面跟的是command命令,它的终止是以;为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。
{} 花括号代表前面find查找出来的文件名。
使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的。在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令,需要测试。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令 删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文 件名。
看几个例子:
- 把所有普通文件复制到~/tmp/目录下
- ~$find . -type f -print -exec cp {} ~/tmp/ \;
- 复制文件内容到当前目录所有普通文件
- find . -type f -print -exec cp ~/route {} \;
- find . -type f -print -exec rm {} \;
参考:
find命令应用exec及xargs的更多相关文章
- find命令之exec和xargs
exec: find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是c ...
- 关于 ‘--exec’ 参数( find 命令)及介绍 ‘xargs ’命令区别(新版)
前言: find 命令一直都是系统管理员的常用命令之一, 其参数中 "-exec" 尤其实用.而 "xargs" 命令,针对查询也有属于自己的见解.本文着重讲解 ...
- linux中exec和xargs命令的区别和优劣分析
find的exec及ok命令 exec命令的格式为: exec command {} \; exec后面跟着的是操作命令,然后跟着{}表示每一个参数,然后空格,然后"\;".{}之 ...
- exec与xargs区别
区别描述: 两者都是对符合条件的文件执行所给的Linux 命令,而不询问用户是否需要执行该命令. -exec:{}表示命令的参数即为所找到的文件,以:表示comman命令的结束.\是转义符,因为分号在 ...
- 每天一个 Linux 命令(20):find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- 每天一个linux命令(20):find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- linux find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- PHP执行系统外部命令函数:exec()、passthru()、system()、shell_exec()
php提供4种方法执行系统外部命令:exec().passthru().system(). shell_exec().在开始介绍前,先检查下php配置文件php.ini中是有禁止这是个函数.找到 di ...
随机推荐
- uv计算
lightmap shadowmap heightmap 它们有一个自己的camera 对应cameraMatrix float3 TransfromToTextureCoord(float4 Pos ...
- 《jQuery基础》总结
目前,互联网上最好的jQuery入门教材,是Rebecca Murphey写的<jQuery基础>(jQuery Fundamentals).这本书虽然是入门教材,但也足足有100多页.我 ...
- VMware(bridge、NAT、host-only、custom)含义
摘自: http://www.liangston.com/?post=48 VMware(bridge.NAT.host-only.custom)含义 作者:LiangSton 发布于:2012-1- ...
- [转]php中实现事件驱动
原文: https://blog.csdn.net/yhl27/article/details/8705313 -------------------------------------------- ...
- 014敲代码将一个栈按升序排序,对这个栈是怎样实现的,你不应该做不论什么特殊的如果(keep it up)
敲代码将一个栈按升序排序. 对这个栈是怎样实现的,你不应该做不论什么特殊的如果. 程序中能用到的栈操作有:push | pop |isEmpty 最easy想到的就是优先队列来做此题.easy实现. ...
- Node.js monly图片批量下载爬虫1.00
此爬虫又用到了iconv转码,代码如下: //====================================================== // mmonly图片批量下载爬虫1.00 ...
- iOS NSFileManager对沙盒文件及目录添加删除操作
iOS 使用 NSFileManager对沙盒里面的文件和目录,增加,修改,删除操作: - (void)viewDidLoad { [super viewDidLoad]; self.title = ...
- 关于android-support-v4.jar包的错误
1.加入android-support-v4 误 java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in load ...
- Spring-1 之入门
(一)简单对象Spring XML配置说明 使用Spring (Spring 3.0) 实现最简单的类映射以及引用,属性赋值: 1.1.新建类UserModel: 1 2 3 4 5 6 7 8 9 ...
- Vue 作用域插槽
使用场景:复用子组件的slot,又可以使slot的内容不一样. <!DOCTYPE html> <html lang="zh"> <head> ...