位置: 编程技术 - 正文

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

  • 税务清算都交什么费用
  • 房屋用途 居住用房 住宅 区别
  • 个体工商户定期定额征收个人所得税
  • 交所得税用计提吗
  • 税务定税按什么标准
  • 发票在系统里作用大吗
  • 外币账户单位基本情况表
  • 员工借款业务流程
  • 乙方收到甲方项目建设工程款如何记账
  • 合伙律师事务所的合伙人必须是
  • 利息发票怎么算
  • 经营所得预缴申报时间
  • 代收污水处理费免税
  • 存货暂估入账需要什么单据?
  • 电梯生产设备
  • 公允价值确定方法最新
  • 如何计算应交税
  • 可供出售金融资产和交易性金融资产
  • 外经证预缴税款之后剩下的税款交到哪呢
  • 免税商品销售要缴税吗
  • 统一员工行为规范
  • 包装物计入科目
  • 研发支出与开发成本的区别
  • 增值税进项大于销项月末需要结转吗
  • php中提交表单数据
  • 不符合条件的数据
  • 自产货物用于销售
  • 房地产企业哪些成本上升了
  • window10黑白模式
  • PHP:pg_send_query_params()的用法_PostgreSQL函数
  • 会计准则新规
  • php的难点
  • CNN+LSTM+Attention实现时间序列预测(PyTorch版)
  • 收取职工交来伙食费如何入账
  • 只有收据没有发票怎么报销
  • php批量替换
  • php正则函数内容匹配
  • php 进程通信
  • 累计应缴预缴所得税怎么算
  • vue项目引入axios
  • php json格式
  • 打开的ps关不掉
  • 301重定向到https 并且不带www跳转到带www
  • 材料采购会计科目怎么使用
  • vue–router
  • 房地产企业年报数据
  • 个体户个税计算公式
  • 办理对公账户时间
  • 企业所得税报表查询怎么查
  • 小规模进项是专票销项是普票可以抵扣吗
  • 营业执照丢失公告后几天可以办注销
  • 2019年无形资产的摊销额为
  • 印花税是必交的吗
  • 工会经费计提基数包括福利费吗
  • 汇算清缴前取得发票可以税前扣除吗
  • 固定资产发票未到可以确认固定资产吗
  • 个人微信转账可以给对方开发票吗
  • mysql批量删除数据库死锁
  • vb.net invoke
  • VMware虚拟机中卸载java命令
  • fedora workstation怎么安装
  • kvm虚拟化网络配置
  • winxp怎么做系统
  • win7系统玩暗黑2怎样全屏
  • 如何升级win
  • win8待机后无法唤醒
  • win10的蓝屏界面
  • 如何解决win10系统重置卡在62
  • javascript声明变量的语句
  • shell脚本的fi
  • unity c#开发
  • javascript toggle
  • jquer选择器
  • 音频资料下载
  • 国家税务电子发票查验入口
  • 企业招用退役士兵
  • 如何在国税网上做企业会计制度备
  • 航空煤油消费税征收环节
  • 失业金存在多个账户
  • 辽宁网上税务
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设