位置: 编程技术 - 正文

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 命令详解)

  • 增值税发票认证在哪里
  • 土地增值税特点不包括
  • 以经营房产投资合营收固定收益如何开发票?
  • 赠品要做视同销售申报纳税吗
  • 软件 折旧年限
  • 建筑行业预缴增值税可以用进项抵缴吗
  • 个税累计扣除项目合计2712.5是什么
  • 知识产权局专利审查协作中心
  • 公司出租非自有房产
  • 公积金贷款购房后可以提取公积金吗
  • 外购产品对外捐赠的会计处理
  • 公司利润如何提取避税
  • 收就业局稳岗补贴做账
  • 房地产收到客户房款如何做账
  • 驻外人员医保报销
  • 应收账款补提坏账是什么意思
  • 借方增加的科目记忆口诀
  • 材料采购成本差异属于什么科目
  • 关于保险机构代收车船税开具增值税发票问题的公告
  • 小微企业免征增值税报表填写
  • 代开的发票没有打印怎么作废
  • 在建工程摊销是啥意思
  • 行政单位以前年度会计错账调整
  • 以前年度损益调整编码
  • 4S店装修改造费帐务处理?
  • 想买黄金投资怎么做
  • 询证函是什么文书
  • 银行手续费填在汇算清缴的哪个表
  • 收到别的公司对公转账往来
  • win7对话框文本框在哪里
  • win11怎么打开虚拟内存
  • 将自产的应税消费品用于非应税项目
  • 7zip怎么压缩文件为rar
  • Win11 Build 22000.348更新补丁KB5007262预览版发布(附更新修复内容汇总)
  • 深度linux使用入门教程
  • 建筑企业项目部开户
  • 事件循环(Event Loop)
  • 项目竣工决算审计与工程结算审核的区别是
  • echarts地图参数设置
  • 花卉苗木栽培技术
  • 如何在vue项目中禁止谷歌浏览器改变网页颜色
  • 怎样安装∪sb
  • 帝国cms自动更新
  • 现行印花税税率是多少
  • 公司基本户里的钱有利息吗
  • 长期股权投资收益要交税吗
  • 进项税额是意思
  • 销售退回采购方的会计分录
  • 未认证进项税额会计分录
  • 收到社保局的稳岗通知
  • 实际验收入库是什么科目
  • 资产评估增值的调整方法
  • 实收资本没到账缴纳印花税吗
  • 无发票入账违反什么规定
  • 自制半成品销售方案
  • 用友软件如何反结账流程
  • 消防设施 房产税
  • 建筑工地塔吊租赁会计分录
  • 年度的汇算清缴
  • 解决windows update问题
  • mac怎么复制文件路径地址
  • linux安装.sh
  • wpl是什么文件
  • linux管道与重定向
  • win8系统截图工具快捷键
  • Win10年度升级版Redstone来了:更加个人化的计算体验
  • shell备份文件脚本
  • opengl 有哪些特点?与directx相比它有什么不同?
  • 如何理解闭包,闭包的优缺点
  • 用jquery制作轮播图效果
  • 如何使用css设置元素的层叠效果?
  • javascript cookies
  • python调用python脚本
  • javascript的
  • js中如何弹出提示框
  • 常规巡察和专项巡察相结合
  • 出口退税的期限是多长
  • 纳税人有什么影响
  • 房地产的土地增值税怎么交
  • 中国税务局发票
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设