位置: 编程技术 - 正文

linux系统中find命令之exec使用介绍(linux里find命令)

编辑:rootadmin

推荐整理分享linux系统中find命令之exec使用介绍(linux里find命令),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:linux系统find命令用法,linux find -name命令详解,linux find -name 命令,linux find -mmin,linux里find命令,linux系统find命令用法,linux系统中find命令,linux系统find命令用法,内容如对您有帮助,希望把文章链接给更多的朋友!

find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作,这个时候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.loglrwxrwxrwx 1 root root 7 - : log_link.log -> log.log-rw-r--r-- 1 root root - : log.log-rw-r--r-- 1 root root - : log.txtdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 2 root root - : test4[root@localhost test]# find . -type f -mtime + -exec rm {} ;[root@localhost test]# ll总计 -rw-r--r-- 1 root root - : log.loglrwxrwxrwx 1 root root 7 - : log_link.log -> log.logdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 2 root root - : test4[root@localhost test]#

说明:

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

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

命令:

linux系统中find命令之exec使用介绍(linux里find命令)

find . -name "*.log" -mtime +5 -ok rm {} ;

输出:

复制代码代码如下:[root@localhost test]# ll总计 -rw-r--r-- 1 root root - : log.loglrwxrwxrwx 1 root root 7 - : log_link.log -> log.logdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 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.logdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 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/bashroot:x:0:0:root:/root:/bin/bash[root@localhost test]#

说明:

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

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

命令:

find . -name "*.log" -exec mv {} .. ;

输出:

复制代码代码如下:[root@localhost test]# ll总计 drwxr-xr-x 6 root root - : scfdrwxrwxr-x 2 root root - : test3drwxrwxr-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.logdrwxr-xr-x 6 root root - : scfdrwxrwxr-x 2 root root - : test3drwxrwxr-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.logdrwxr-xr-x 6 root root - : scfdrwxrwxr-x 2 root root - : test3drwxrwxr-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命令之xargs使用实例分享 错误信息通常是参数列太长或参数列溢出。这就是xargs命令的用处所在,特别是与find命令一起使用。find命令把匹配到的文件传递给xargs命令,而xargs命令

linux命令之find命令的个常用参数详解(含具体用法和注意事项) 1.使用name选项:文件名选项是find命令最常用的选项,要么单独使用该选项,要么和其他选项一起使用。可以使用某种文件名模式来匹配文件,记住要

linux命令大全之crontab命令使用详解 at命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由cron(crond)这个系统服务来控制的。Linux系统上面原本就有非常多的计划性工

标签: linux里find命令

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

上一篇:linux中locate命令使用介绍(快速搜寻档案)(linux中locate命令的作用)

下一篇:linux系统find命令之xargs使用实例分享(linux 中find)

  • 已抵扣进项税额转出怎么申报
  • 增值税留抵退税是什么意思
  • 个人以房产投资企业需要过户吗
  • 应收账款贷方有余额是什么意思
  • 小规模什么情况下只交城建税
  • 工资代扣工会会费
  • 实收资本的印花税怎么交
  • 银行贷款减值准备转回处理
  • 资产负债表负债总额怎么看
  • 小企业固定资产折旧的账务处理
  • 两免三减半的概率是多少
  • 工程实际成本核算例题
  • 接受股权转让要交什么税
  • 股权转让金是什么意思
  • 采购折扣怎么结转成本?
  • 企业资产业务收购税务处理怎么做?
  • 现金报销银行账户
  • 补税款的分录应该怎么写
  • 对外投资增长过快
  • 生活服务的发票可以报销吗
  • 合作社开具的免税普票计算抵扣
  • 合作方寄来的礼物能不能收?
  • 资产负债表资产总额在哪
  • 营业收入现金怎么计算
  • 股东收回投资款的现金流量
  • 打开我的电脑出现找不到应用程序
  • 网络命令netstat
  • php开发的优点与不足
  • fsrec.sys
  • element ui datepicker 源码
  • php动态网站开发项目教程
  • 存货跌价准备是什么意思
  • 金银首饰零售业税负率是多少
  • asreg命令什么意思
  • JavaScript DOM API的使用
  • php数据表
  • 预付账款年底怎样结转
  • columninfo
  • php中为什么图片显示不出来
  • 年末应交税费怎么算
  • 销项和进项税额还需要月底转出么
  • 美容店销售收入预测表12个月表格
  • phpcms怎么用
  • c语言中数组怎么用
  • 结余资金包括结转资金吗?
  • 法人治理结构是指明确
  • 非税收入统一票据怎么查询
  • 服务费可以计入主营业务成本吗
  • 端午节发放的现金福利会计处理
  • 汇算清缴退税分录怎么做
  • 个人独资企业个体工商户的区别
  • 金税盘技术维护费
  • 技术咨询服务开票代码
  • 开出口未开出口怎么办
  • 本期应征增值税销售额是什么意思
  • 电子记账凭证需要划线吗
  • mysql安装配置教程5.7.16
  • 最全的sql执行顺序
  • windows vista可以换7吗
  • win8 开机启动
  • office2013标准版
  • linux bfs
  • ExtJS 2.0实用简明教程 之Border区域布局
  • js调用xml
  • 安卓icon图标
  • core文件的作用
  • xcopy /s /e
  • 如何用dos修复引导
  • jquery移动端ui框架
  • android数据存储实验报告
  • jquery鼠标移入
  • js实现fizzbuzz
  • 云南省税务局app缴费
  • 税务 涉税中介
  • 收到补税点的分录
  • 四川灵活就业医保每月返多少钱
  • 办理出口退税需要销售合同吗
  • 放管服中的服的深层含义
  • 税务培训主题
  • 增值税专用发票和普通发票的区别
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设