位置: 编程技术 - 正文

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

  • 买房契税如何计算
  • 幼儿园营业税税率是多少
  • 税务师考几科几分及格
  • 员工交通费可以税前扣除吗
  • 开办期的所得税年度申报
  • 烟丝是消费税的征收范围
  • 小微企业所得税税率2.5% 10% 25%
  • 稿费计入成本怎么做账
  • 企业注销的时候未分配利润怎么处理
  • 跨月应该如何开具红字发票?
  • 企业职工遣散费标准
  • 从国外购进样品要交税吗
  • 公司向贷款公司贷款做账分录
  • 什么样的企业用交税
  • 开餐饮发票的经营范围是怎样的?
  • 跨省非独立核算分公司如何报税
  • 增值税发票开票限额怎么申请?
  • 关税完税价格包含关税吗
  • 股东向公司借款需要交税吗
  • 土地增值税怎么预交
  • 借款利息资本化金额
  • 投资性房地产后续支出包括
  • 劳务成本月底有余额吗
  • 非税收入的发票能抵扣吗
  • 出纳备用金收支登记表怎么做
  • 公司支付的赔偿款计入什么会计科目
  • 资产负债表流动性从强到弱
  • windows10软件图标不正常显示
  • windows7中
  • PHP:xml_get_current_byte_index()的用法_XML解析器函数
  • thinkphp5框架介绍
  • ajax实现分页
  • 转出未交增值税和未交增值税区别
  • 包装物押金收入是否计入销售额
  • laravel debug rce
  • vue每一列内容过多自动换行
  • framework7教程
  • 业务招待费用列支范围
  • php抓取网页图片
  • php一个页面多个分页
  • react组件库有哪些
  • idea2020.2.3创建web
  • 损失函数解读例题
  • 计提社保会计分录金额怎么写
  • 进货退出进项税额的核算
  • 印花税缴纳方式不包括哪些
  • 调账处理
  • mongodb 日志
  • Philtron: a PHP Proxy for HTTP
  • 消费税为什么要除以1减税率推导公式
  • 增量留底退税怎么比增值税高
  • 印花税免税项目有哪些
  • 增值税普票可以开给个人吗
  • 个体户单位性质代码
  • 小规模个体工商户怎么交税
  • 金蝶kis云专业版使用教程
  • 计提附加税费是什么意思
  • 商业购进商品运费怎么算
  • 我国现行资源税主要采用什么税率
  • 资产利润率在1104哪个表
  • 机械租赁公司需要什么证件
  • 没有认证的进项税额怎么做凭证
  • 劳务分包企业收入怎么算
  • 商业企业会计分录大全
  • MySQL-tpch 测试工具简要手册
  • sql中存储过程的用法
  • ubuntu20桌面
  • mac浏览器显示不全
  • 进程dwm
  • win7打开游戏显示已停止工作
  • win70x80073712解决方法
  • 数字小键盘不管用
  • 炉石 xhope
  • python实现识别相似图片小结
  • javascript数组有哪些方法
  • javascript基础入门视频教程
  • vim合并两个文件
  • js实现的倒计时怎么用
  • 四川志愿服务注册入口
  • 江西鹰潭潭花酒60度
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设