位置: 编程技术 - 正文

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命令用法)

  • 个税返还奖励财务人员流程
  • 当月认证了进项票没用完下个月还可以用吗
  • 消费税应该怎么缴纳
  • 应交所得税的计税依据
  • 固定资产特性
  • 商铺售后返租的会计分录
  • 损益类科目计入哪个表
  • 报废资产处置收入怎么计税
  • 公司购买短期理财现金流量表怎么填
  • 税控盘这个月没有反写会怎么样
  • 企业所得税年报更正申报
  • 旧的活动板房多少钱一个
  • 个人独资企业生活费用和经营费用混在一起的
  • 个体工商户变更法人
  • 移动通信定额发票
  • 结算银行贷款利息用什么凭证
  • 发票认证只认证进项吗
  • 坏账准备什么时候转回
  • 苹果手机m开头的序列号代表什么
  • excel中在多个单原格中输入相同数据
  • mac死机什么原因
  • 经营租赁方式租入分录
  • 修改hosts文件的软件
  • 吊兰怎么养才能开花
  • windows10版本2004怎么样
  • 深入理解php内核
  • ireike.exe - ireike是什么进程 有什么作用
  • 栀子花叶子发黄是什么原因
  • 产品出库单什么时候入账
  • 外商投资企业法人独资属于内资还是外资
  • 公司注销后虚开能查吗
  • 房地产企业土地出让金抵减销项税额
  • php面向过程
  • 确认的政府补助利得可以确认为收入吗
  • vue路由的理解
  • libev & libevent简介 IntelIOT 博客园
  • 报销还款人民币是什么意思
  • 用于app服务端的加速器
  • 零申报失败什么原因
  • 合营企业和联营企业都是权益法吗
  • 库存盘盈处理
  • 融资租赁开什么发票
  • 自然人独资交企业所得税吗
  • 个体户该怎么交公积金
  • 营改增后土地出让增值税
  • 应收账款无法收回会计分录
  • 个税新增人员工资怎么填
  • 技术服务费计入主营业务成本
  • 小规模纳税人收入是含税还是不含税
  • 融资租赁本金和租金的区别
  • 没有对公业务的银行
  • 企业注销以后
  • 流动资产周转率计算公式
  • 没有光驱启动
  • linux系统讲解
  • centos安装ntfs 3g
  • linux中dhcp
  • u盘制作winpe启动盘
  • mbr是什么启动
  • windows磁盘工具
  • win10怎么清理系统垃圾
  • linux常用配置
  • win7旗舰版系统还原无法启动
  • jquery22插件网
  • cocos2djs
  • 如何解决焦虑的心理
  • python的入门教程
  • nodejs增删改查
  • 遮罩有什么作用
  • 批量ssh登录
  • js中的
  • [置顶]电影名字《收件人不详》
  • 广州出租车发票号码在哪里
  • 贵州省税务网上缴费平台
  • 税务安装步骤
  • 北京市国家税务局网站官网
  • 如果快递没有按时发货东西变质怎么办
  • 南京市国家税务局官网
  • 淮北市国家税务总局电话
  • 如何进行税务筹划工作
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设