位置: 编程技术 - 正文

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

  • 自行研发的无形资产不确认递延所得税
  • 应付账款转资本公积
  • 加班费计入个税吗
  • 红冲以后怎么做账
  • 餐饮服务需要缴纳增值税吗
  • 去年的亏损今年第一季度可以弥补吗
  • 取得保险赔偿的会计分录
  • 营改增后个人所得税计税依据实例
  • 收到发票冲预付账款摘要怎么写
  • 销售现金券会计分录
  • 企业购买的黄金计入什么科目
  • 季度开票超过9万个人所得税
  • 总公司要合并分公司报表吗
  • 海关增值税抵扣是全额抵扣所得税
  • 在建工程需要交哪些税
  • 汽车折旧年限与什么有关
  • 收到供应商开具什么发票
  • 单位有临时工工资怎么发
  • 国家税务总局关于取消增值税扣税凭证
  • 留抵进项税额可以挂在转出未交增值税吗
  • 退税技术有什么影响
  • 智能化的发展现状与趋势
  • 怎么利用腾讯手机号找人
  • 鸿蒙系统怎么切换回安卓
  • 企业对外捐赠的税法处理
  • 投标保证金利息怎么做账
  • linux内核有什么作用
  • 房产证工本费怎么做账
  • 限额领料单属于外来原始凭证吗
  • PHP:pg_result_status()的用法_PostgreSQL函数
  • 取得专票怎么结转销售成本
  • 哈勃太空望远镜取得的部分成果有哪些
  • 外贸企业进项发票能是外贸企业吗
  • php db2
  • 前端播放视频的插件
  • 微信小程序如何删除
  • read命令 linux
  • 承租方承担的税费是多少
  • 固定资产投资账面价值
  • c++评测
  • 酒店没有营业执照开业犯法吗
  • 残疾人就业保证金上年工资总额是说上一年度么
  • 普通发票记账联丢了怎么解决
  • 购买方如何申请红字信息表填写负数吗
  • 上年度多提财务费用
  • 应收账款的会计要素
  • 免税小规模企业增值税申报表怎么填
  • 关于利润分配科目的表述正确的有
  • 小规模转一般纳税人条件最新政策
  • 行政事业单位支出范围和标准
  • 资产负债表中负债的排列依据是
  • 跨境汇款汇错
  • 什么是计提坏账准备
  • 建账的内容一般包括什么
  • win8怎么让我的电脑显示在桌面上
  • centos crontab每天执行
  • win7系统开启vt
  • win7系统文件夹怎么加密码
  • Win8系统筛选器Smartscreen阻止恶意程序运行
  • linux 查看磁盘io繁忙
  • ubuntu 重启xorg
  • win8系统远程桌面在哪里
  • Linux>=2.6.39 Mempodipper本地提权分析和EXP利用(CVE-2012-0056)
  • 宏基win8改win7
  • linux安装docker-compose
  • Unable to execute dex: Multiple dex files define Lorg/cocos2dx/lib/Cocos2dxAccelerometer
  • unity3d游戏引擎支持几种平台发布?
  • android!
  • shell中for循环如何用sed
  • python装饰器与递归算法详解
  • 不想让浏览器运行
  • jquery easyui从零开始学pdf
  • python多进程多线程协程
  • mixed模型
  • 税务局网上申请开票
  • 如何打印个人所得税证明
  • 广东电子税务局电话
  • 纳税申报期限2023
  • 开红酒增值税票怎么开
  • 绵阳税务局咨询电话
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设