位置: 编程技术 - 正文

Linux find命令中-exec参数的作用介绍(linux命令find用法)

编辑:rootadmin

推荐整理分享Linux find命令中-exec参数的作用介绍(linux命令find用法),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:在linux中find命令,在linux中find命令,linux find -cmin,linux find -o,linux find -o,linux find -cmin,linux find -cmin,linux find命令详解xargs,内容如对您有帮助,希望把文章链接给更多的朋友!

  我们都知道,Linux命令加上不同的参数其效果也不同,下面小编将针对Linux fing命令中的-exec 参数给大家做个详细介绍,以便你有个了解。

  exec解释:

  -exec 参数后面跟的是command命令,它的终止是以;为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。

  {} 花括号代表前面find查找出来的文件名。

  使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的。在有些操作系统中只允许-exec选项执行诸如l s或ls -l这样的命令。大多数用户使用这一选项是为了查找旧文件并删除它们。建议在真正执行rm命令删除文件之前,最好先用ls命令看一下,确认它们是所要删除的文件。 exec选项后面跟随着所要执行的命令或脚本,然后是一对儿{ },一个空格和一个,最后是一个分号。为了使用exec选项,必须要同时使用print选项。如果验证一下find命令,会发现该命令只输出从当前路径起的相对路径及文件名。

  实例1:ls -l命令放在find命令的-exec选项中

  命令:

  find 。 -type f -exec ls -l {} ;

  输出:

  代码如下:

  [root@localhost test]# find 。 -type f -exec ls -l {} ;

  -rw-r--r-- 1 root root - : 。/log.log

  -rw-r--r-- 1 root root 0 - : 。/test4/log3-2.log

  -rw-r--r-- 1 root root 0 - : 。/test4/log3-3.log

  -rw-r--r-- 1 root root 0 - : 。/test4/log3-1.log

  -rw-r--r-- 1 root root - : 。/log.log

  -rw-r--r-- 1 root root - : 。/log.log

  -rw-r--r-- 1 root root - : 。/log.log

  -rw-r--r-- 1 root root - : 。/log.txt

  -rw-r--r-- 1 root root 0 - : 。/test3/log3-2.log

  -rw-r--r-- 1 root root 0 - : 。/test3/log3-3.log

  -rw-r--r-- 1 root root 0 - : 。/test3/log3-1.log

  [root@localhost test]#

  说明:

  上面的例子中,find命令匹配到了当前目录下的所有普通文件,并在-exec选项中使用ls -l命令将它们列出。

  实例2:在目录中查找更改时间在n日以前的文件并删除它们

  命令:

  find 。 -type f -mtime + -exec rm {} ;

  输出:

  代码如下:

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  lrwxrwxrwx 1 root root 7 - : log_link.log -》 log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.txt

  drwxr-xr-x 6 root root - : scf

  drwxrwxrwx 2 root root - : test3

  drwxrwxrwx 2 root root - : test4

  [root@localhost test]# find 。 -type f -mtime + -exec rm {} ;

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  lrwxrwxrwx 1 root root 7 - : log_link.log -》 log.log

  drwxr-xr-x 6 root root - : scf

  drwxrwxrwx 2 root root - : test3

  drwxrwxrwx 2 root root - : test4

  [root@localhost test]#

  说明:

  在shell中用任何方式删除文件之前,应当先查看相应的文件,一定要小心!当使用诸如mv或rm命令时,可以使用-exec选项的安全模式。它将在对每个匹配到的文件进行操作之前提示你。

  实例3:在目录中查找更改时间在n日以前的文件并删除它们,在删除之前先给出提示

  命令:

  find 。 -name “*.log” -mtime +5 -ok rm {} ;

  输出:

  代码如下:

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  lrwxrwxrwx 1 root root 7 - : log_link.log -》 log.log

  drwxr-xr-x 6 root root - : scf

  drwxrwxrwx 2 root root - : test3

  drwxrwxrwx 2 root root - : test4

  [root@localhost test]# find 。 -name “*.log” -mtime +5 -ok rm {} ;

  《 rm 。。。 。/log_link.log 》 ? y

  《 rm 。。。 。/log.log 》 ? n

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

Linux find命令中-exec参数的作用介绍(linux命令find用法)

  drwxr-xr-x 6 root root - : scf

  drwxrwxrwx 2 root root - : test3

  drwxrwxrwx 2 root root - : test4

  [root@localhost test]#

  说明:

  在上面的例子中, find命令在当前目录中查找所有文件名以.log结尾、更改时间在5日以上的文件,并删除它们,只不过在删除之前先给出提示。按y键删除文件,按n键不删除。

  实例4:-exec中使用grep命令

  命令:

  find /etc -name “passwd*” -exec grep “root” {} ;

  输出:

  代码如下:

  [root@localhost test]# find /etc -name “passwd*” -exec grep “root” {} ;

  root:x:0:0:root:/root:/bin/bash

  root:x:0:0:root:/root:/bin/bash

  [root@localhost test]#

  说明:

  任何形式的命令都可以在-exec选项中使用。在上面的例子中我们使用grep命令。find命令首先匹配所有文件名为“ passwd*”的文件,例如passwd、passwd.old、passwd.bak,然后执行grep命令看看在这些文件中是否存在一个root用户。

上一页下一页共3页

  实例5:查找文件移动到指定目录

  命令:

  find 。 -name “*.log” -exec mv {} 。。 ;

  输出:

  代码如下:

  [root@localhost test]# ll

  总计 drwxr-xr-x 6 root root - : scf

  drwxrwxr-x 2 root root - : test3

  drwxrwxr-x 2 root root - : test4

  [root@localhost test]# cd test3/

  [root@localhost test3]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root 0 - : log.log

  [root@localhost test3]# find 。 -name “*.log” -exec mv {} 。。 ;

  [root@localhost test3]# ll

  总计 0[root@localhost test3]# cd 。。

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root 0 - : log.log

  drwxr-xr-x 6 root root - : scf

  drwxrwxr-x 2 root root - : test3

  drwxrwxr-x 2 root root - : test4

  [root@localhost test]#

  实例6:用exec选项执行cp命令

  命令:

  find 。 -name “*.log” -exec cp {} test3 ;

  输出:

  代码如下:

  [root@localhost test3]# ll

  总计 0[root@localhost test3]# cd 。。

  [root@localhost test]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root 0 - : log.log

  drwxr-xr-x 6 root root - : scf

  drwxrwxr-x 2 root root - : test3

  drwxrwxr-x 2 root root - : test4

  [root@localhost test]# find 。 -name “*.log” -exec cp {} test3 ;

  cp: “。/test3/log.log” 及 “test3/log.log” 为同一文件

  cp: “。/test3/log.log” 及 “test3/log.log” 为同一文件

  cp: “。/test3/log.log” 及 “test3/log.log” 为同一文件

  [root@localhost test]# cd test3

  [root@localhost test3]# ll

  总计

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root - : log.log

  -rw-r--r-- 1 root root 0 - : log.log

  [root@localhost test3]#

  上面就是Linux find命令中-exec参数的用法介绍了,find命令的参数还有很多,如果你还想了解其他参数的使用,详见Linux find命令中-path -prune参数的作用介绍。

Linux find命令中-path -prune参数作用详细介绍 Linux下find命令拥有多种查找方式,那么find命令中加上-path-prune参数会怎么样呢?下面小编就给大家介绍下find命令中-path-prune的用法。假如在当前目录下

在Linux下如何安装配置fcitx输入法 Linux输入法的切换和Windows一样,也可使用快捷切换,fcitx输入法是众多输入法中的一种,有些朋友习惯使用该输入法,下面小编就给大家介绍下Linux如何

Linux如何使用locate命令查找数据查找指定文件 locate命令是Linux查找命令中的一种,可用于查找数据,与find命令有些相似,但find命令更加消耗资源,下面小编就给大家详细介绍下locate命令的用法。loca

标签: linux命令find用法

本文链接地址:https://www.jiuchutong.com/biancheng/368324.html 转载请保留说明!

上一篇:Linux学习笔记(三):磁盘和文件系统管理(linux learn)

下一篇:Linux find命令中-path -prune参数作用详细介绍(linux中find命令用法)

  • 免费样品需要交印花税吗
  • 税控盘当月不抵扣怎么申报
  • 增值税扣费
  • 没有达到起征点的工资忘计申报个税,可以税前扣除吗
  • 税控盘丢失需要罚款吗
  • 叉车需要购置税吗
  • 业务招待费超支原因怎么写
  • 免费样品销售给客户计入什么科目
  • 购入货物自用的进项税额转出分录怎么处理
  • 税务局退税收入多久到账
  • 餐饮发票可以抵扣个人所得税吗
  • 农产品收购发票是普票还是专票
  • 去新建的外贸公司好不好
  • 提取备用金的手续费会计分录
  • 补缴去年附加税及滞纳金
  • 企业的财产清查无论什么情况,均应先通过
  • 事业单位转账支票管理
  • 个体户营业收入超过500万
  • 没有签订合同需要申报印花税吗
  • 税务局报表利润表本期金额
  • 不同方式的融资租赁业务如何贴花?
  • 年初未分配利润是什么科目
  • 逆流交易合并报表调整少数损益
  • 利息股息红利所得属于综合所得吗
  • pc direct
  • php常用的设计模式在开发中的实例
  • 分公司不纳入合并
  • kavsvc.exe - kavsvc是什么进程 有什么作用
  • sbdrvdet.exe - sbdrvdet是什么进程 有什么用
  • gwsystemservice.exe是什么进程 有什么作用 gwsystemservice进程查询
  • php简单聊天室源码
  • 酒店开业前准备工作流程
  • 房地产开发企业增值税怎么算
  • php取二维数组的一组内容
  • 公司员工社保由总公司代缴证明
  • yolov3数据集格式
  • php操作mysql数据库的扩展有哪三个
  • 微信小程序制作
  • php字符串包含某个字符串
  • 公司上市的好处
  • 开源cti
  • 什么是异步函数
  • 原材料的采购成本主要包括有?
  • 进口设备增值税计算
  • 长期股权投资核算的成本法与权益法的主要差别有哪些
  • mysql数据库查询表命令
  • 如何使用灭火器的方法
  • 融资租赁租金计算工具使用的主要过程
  • 出口退税帐务处理
  • 房产增值税发票可以抵税吗
  • 会计库存商品属于什么科目
  • 怎么才能回到一年前
  • 个体户记账报税
  • 应付工资可以挂账多长时间
  • 公司开发的app费用怎么算
  • 企业设备维修
  • 冲销凭证如何做分录
  • 税务局三代手续费是什么
  • 企业商品销售收入确认条件
  • 车辆租赁费发票怎么开
  • 航天开票系统怎么导出已开票明细
  • win10下载mysql图解
  • linux下mysql5.7.17最新稳定版本安装教程
  • Fedora 21顶栏日期显示不全的解决方法
  • win10和os x el capitan分屏操作对比视频
  • linux系统批量替换内容
  • win8如何免费升级win10
  • cocos2dx环境搭建
  • 开快打开
  • JavaScript的strict模式与with关键字介绍
  • 支持向量机
  • [置顶]马粥街残酷史
  • 安卓手机都这样
  • Android使用opencv处理图片灰度
  • python 字典的字典
  • 税务局监察室主任职位说明书
  • 重庆市劳动监察大队官网
  • 中国一年能收多少税
  • 广州市地税服务大厅
  • 赞美税务局的话
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设