位置: 编程技术 - 正文

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

  • 社保个人承担部分
  • 公司亏损汇算清单模板
  • 城市维护建设税的计税依据是什么
  • 出租的土地使用权是无形资产吗
  • 个体工商户怎么注册
  • 劳务派遣 税务
  • 应纳税所得额就是企业所得税吗
  • 结转损益主营业务成本在借方还是贷方
  • 网上缴税后会有发票吗
  • 房产契税新政策消息2023
  • 弥补以前年度亏损税局会查吗
  • 雇主责任险可以税前扣除吗
  • 物流分公司怎么运作
  • 纳税人识别号在哪里能查到
  • 三类小规模纳税标准
  • 劳务费个人还需要交税吗
  • 房地产开发企业需要缴纳哪些税
  • 离退休人员福利
  • 发票需要写真名吗
  • 个人股权转让如何申报个人所得税
  • 预提费用年终有余额怎么办
  • 桌面图标间距特别大
  • 咨询服务费怎么交税
  • 股权处置的形式
  • 财务费用为什么增加
  • 完税证明和纳税申报表的金额不一致
  • johnny kim宇航员
  • 猫鼬家族风云
  • 触屏不灵敏怎么调整oppo
  • vue前端代码实例
  • framework在哪里打开
  • 什么是AI工具
  • 盒子模型的概念
  • 初级会计直线法摊销
  • 显示已申报未导入
  • 固定资产有金额界定吗
  • spring框架使用教程
  • 织梦怎么建站
  • 出售无形资产科目
  • 建筑工程机械设备租赁属于什么行业
  • 预期信用损失率的确认依据和过程
  • 小规模季度超过45万了怎么缴纳
  • 工厂加工费如何计算
  • 营业外收入记入企业的什么
  • 支付股东借款现金流量表怎么填
  • 其他应收款项
  • 工程未竣工预付款怎么办
  • 固定资产卡片项目的数据类型包括
  • 子公司利润母公司还有其他方式吗
  • 什么公司转让需要交税
  • 建筑公司直接把钱打到个人账户怎么走账
  • 营改增租赁服务有哪些
  • 什么是计提坏账准备
  • 残保金不申报可以补缴吗
  • mysql函数用法
  • win7系统安装教程不用u盘
  • Win10预览版怎么变回正式版
  • linux 根目录
  • WIN7系统安装
  • win7系统硬盘
  • ubuntu和windows文件互传
  • 虚拟机远程控制局域网
  • windows7的电脑
  • canvas动态绘制简单gif
  • 深入理解bootstrap
  • Jquery+Ajax+PHP+MySQL实现分类列表管理(下)
  • css英文代码翻译
  • css条件语句
  • Python插件怎么安装
  • javascript按位与
  • shell数值比较
  • javascript类的继承
  • 批处理压缩
  • 七牛云和ucloud
  • shell脚本 -ne 0
  • 技术总结结束语
  • python 面向对象 类
  • 国家税务总局网址
  • 图书行业税率多少
  • 长治一诺代理记账公司
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设