位置: 编程技术 - 正文

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

编辑:rootadmin

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

文章相关热门搜索词:linux里面find命令,linux 中find,linux find命令详解xargs,linux find命令,linux find命令,linux系统find命令查找文件夹,linux系统find命令怎么用,linux系统find命令怎么用,内容如对您有帮助,希望把文章链接给更多的朋友!

错误信息通常是“参数列太长”或“参数列溢出”。这就是xargs命令的用处所在,特别是与find命令一起使用。

find命令把匹配到的文件传递给xargs命令,而xargs命令每次只获取一部分文件而不是全部,不像-exec选项那样。这样它可以先处理最先获取的一部分文件,然后是下一批,并如此继续下去。

在有些系统中,使用-exec选项会为处理每一个匹配到的文件而发起一个相应的进程,并非将匹配到的文件全部作为参数一次执行;这样在有些情况下就会出现进程过多,系统性能下降的问题,因而效率不高; 而使用xargs命令则只有一个进程。另外,在使用xargs命令时,究竟是一次获取所有的参数,还是分批取得参数,以及每一次获取参数的数目都会根据该命令的选项及系统内核中相应的可调参数来确定。

使用实例:

实例1: 查找系统中的每一个普通文件,然后使用xargs命令来测试它们分别属于哪类文件 命令:复制代码代码如下:find . -type f -print | xargs file输出:复制代码代码如下:[root@localhost test]# ll总计 -rw-r--r-- 1 root root - : log.log-rw-r--r-- 1 root root 0 - : log.log-rw-r--r-- 1 root root 0 - : log.logdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 2 root root - : test4[root@localhost test]# find . -type f -print | xargs file./log.log: empty./log.log: empty./log.log: ASCII text[root@localhost test]#

实例2:在整个系统中查找内存信息转储文件(core dump) ,然后把结果保存到/tmp/core.log 文件中

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

命令:复制代码代码如下:find / -name "core" -print | xargs echo "" >/tmp/core.log输出:复制代码代码如下:[root@localhost test]# find / -name "core" -print | xargs echo "" >/tmp/core.log[root@localhost test]# cd /tmp[root@localhost tmp]# ll总计 -rw-r--r-- 1 root root - : core.logdrwx------ 2 root root - : ssh-TzcZDxdrwx------ 2 root root - : ssh-ykiRPkdrwx------ 2 root root - : vmware-root

实例3:在当前目录下查找所有用户具有读、写和执行权限的文件,并收回相应的写权限命令:复制代码代码如下:find . -perm -7 -print | xargs chmod o-w输出:复制代码代码如下:[root@localhost test]# ll总计 -rw-r--r-- 1 root root - : log.log-rw-r--r-- 1 root root 0 - : log.log-rw-r--r-- 1 root root 0 - : log.logdrwxr-xr-x 6 root root - : scfdrwxrwxrwx 2 root root - : test3drwxrwxrwx 2 root root - : test4[root@localhost test]# find . -perm -7 -print | xargs chmod o-w[root@localhost test]# ll总计 -rw-r--r-- 1 root root - : log.log-rw-r--r-- 1 root root 0 - : 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]#说明:执行命令后,文件夹scf、test3和test4的权限都发生改变

实例4:用grep命令在所有的普通文件中搜索hostname这个词命令:复制代码代码如下:find . -type f -print | xargs grep "hostname"输出:复制代码代码如下:[root@localhost test]# find . -type f -print | xargs grep "hostname"./log.log:hostnamebaidu=baidu.com./log.log:hostnamesina=sina.com./log.log:hostnames=true[root@localhost test]#

实例5:用grep命令在当前目录下的所有普通文件中搜索hostnames这个词命令:复制代码代码如下:find . -name * -type f -print | xargs grep "hostnames"输出:复制代码代码如下:[root@peida test]# find . -name * -type f -print | xargs grep "hostnames"./log.log:hostnamesina=sina.com./log.log:hostnames=true[root@localhost test]#说明:注意,在上面的例子中, 用来取消find命令中的*在shell中的特殊含义。

实例6:使用xargs执行mv 命令:复制代码代码如下:find . -name "*.log" | xargs -i mv {} test4输出:复制代码代码如下:[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]# cd test4/[root@localhost test4]# ll总计 0[root@localhost test4]# cd ..[root@localhost test]# find . -name "*.log" | xargs -i mv {} test4[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 test4/[root@localhost test4]# 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 test4]#

实例7:find后执行xargs提示xargs: argument line too long解决方法:命令:复制代码代码如下:find . -type f -atime +0 -print0 | xargs -0 -l1 -t rm -f输出:复制代码代码如下:[root@pd test4]# find . -type f -atime +0 -print0 | xargs -0 -l1 -t rm -frm -f [root@pdtest4]#说明:-l1是一次处理一个;-t是处理之前打印出命令

实例8:使用-i参数默认的前面输出用{}代替,-I参数可以指定其他代替字符,如例子中的[] 命令:输出:复制代码代码如下:[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 test4[root@localhost test4]# find . -name "file" | xargs -I [] cp [] ..[root@localhost test4]# 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 test4]# 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]#说明:使用-i参数默认的前面输出用{}代替,-I参数可以指定其他代替字符,如例子中的[] 实例9:xargs的-p参数的使用 命令:复制代码代码如下:find . -name "*.log" | xargs -p -i mv {} ..输出:复制代码代码如下:[root@localhost test3]# ll总计 0-rw-r--r-- 1 root root 0 - : log.log[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]# cd test3[root@localhost test3]# find . -name "*.log" | xargs -p -i mv {} ..mv ./log.log .. ?...y[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-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]#说明:-p参数会提示让你确认是否执行后面的命令,y执行,n不执行。

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

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

linux命令大全之at命令详解(一次性定时计划任务) 在windows系统中,windows提供了计划任务这一功能,在控制面板-性能与维护-任务计划,它的功能就是安排自动运行的任务。通过'添加任务计划'的一步步

标签: linux 中find

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

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

下一篇:linux命令之find命令的12个常用参数详解(含具体用法和注意事项)(linux find 命令详解)

  • 当月认证了进项票没用完下个月还可以用吗
  • 城建税的征税范围不包括农村对不对
  • 反避税定义
  • 增值税专用发票抵扣期限
  • 土地使用权利
  • 税务安全证书应用客户端
  • 删除申报记录什么意思
  • 分公司缴税企业所得税
  • 生产成本月末转到哪里
  • 设计合同需要缴哪些税
  • 货币形式投资的特点是
  • 财产租赁合同印花税优惠政策
  • 招待费增值税能抵扣吗
  • 外购商品用于促销能抵扣吗
  • 未入账的记账凭证有误处理方法
  • 别人的项目挂靠我公司怎么做账?
  • 前三季度盈利第四季度亏损 所得税记账
  • 业务招待费扣除计算举例说明
  • 金税盘服务费可以当月抵扣吗
  • 纳税人跨县(市、区)是指
  • 房地产企业的非流动资产周转率在多少以上
  • 暂估商品入库跨年收到发票怎么做账?
  • 员工受伤报销
  • 本年利润余额负数表示什么意思
  • 政府投资农业项目
  • 律师费能计入办公费用吗
  • 企业收入确认的依据是什么
  • 苹果取消macbook
  • 客户预付的购货款是收入吗
  • 增值税 劳务费
  • 确认应付职工薪酬是借方还是贷方
  • 如何使用wireshark抓取HTTP数据包?
  • 增值税加计抵减申报表怎么填
  • 集成代码
  • 学堂在线结课后还能看吗
  • 应纳税所得额100-300万税率
  • 上市公司发行股票会计分录
  • 怎么把其他应收款的转到其他应付款
  • 股东出资证明书范本
  • 增值税普通发票查询真伪
  • 红字信息表开错了怎么撤销
  • 一般人转小规模政策到什么时候
  • MyBatis MapperProvider MessageFormat拼接批量SQL语句执行报错的原因分析及解决办法
  • 物流公司扣押货物算犯法吗
  • 一般纳税人每月开票不能超过多少
  • 建筑企业如何按季度申报
  • 个体工商户实收资本可以填0吗
  • 租赁设备如何做会计分录
  • 净资产少于1元
  • 汽车销售公司办理贷款重点调查哪些
  • 商品的结构
  • 半成品会计处理流程
  • 企业进出口总额
  • 贷款应提准备的资料包括
  • 报销程序是什么
  • ubuntu20.04 u盘
  • 搜索不到WiFi信号是怎么回事
  • windowsxp还能正常使用吗
  • 系和系怎么区分
  • linux例子
  • win10更新中途怎么取消
  • wim10飞行模式
  • iphone手机文件怎么传到电脑
  • Windows10系统下iis没有注册.netFrameWork4.0的原因
  • cocos 2d x
  • Extjs EditorGridPanel中ComboBox列的显示问题
  • 有哪些好用的linux
  • 关闭默认共享和共享文件夹
  • perl怎么用
  • perl中@_
  • opengl编程实例
  • 虚拟主机 推荐
  • android界面控件
  • nodejs init
  • shell脚本获取文件指定内容
  • js 表格
  • 信息咨询费包括什么费用
  • 湖北税票真伪查询
  • 加工修理修配统称为什么
  • 企业登录密码是几位数
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设