位置: 编程技术 - 正文

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

  • 工商注册经营部和公司的区别
  • 应交税费是什么会计科目
  • 关联企业的费用包括
  • 金蝶财务系统录入发票
  • 无息贷款合同要按手印吗
  • 增值税主表本期缴纳上期应纳税额需要填数嘛
  • 怎么在网站上打印
  • 发出商品和委托代销商品科目的区别
  • 对公走账是什么意思
  • 非盈利组织是什么
  • 非行政性罚款可以撤销吗
  • 非财政拨款结余是什么科目
  • 资产减值准备会计科目编码
  • 非盈利组织的好处
  • 转售水的税率
  • 工业企业财务核算方法
  • 报价需要提供哪些资料
  • 办事处可以办理临时身份证吗
  • 进口代理公司怎么收费
  • 物业公司取暖费收费标准
  • 吊装费用税率
  • 2017年7月1日开始实施的税法新规
  • 土地+n
  • 费用计入资产
  • 增值税申报错误怎么处理
  • 购买方已认证的专票怎么红冲
  • 即征即退申报表模版
  • 签订租赁合同的期限
  • window11如何打开任务管理器
  • php的类
  • 现金发放的餐补算工资么
  • bellzee.exe是什么
  • messenger 是什么意思
  • 总资产周转次数与总资产周转率
  • framework启动
  • 朱顶雀的饲养
  • 投资者追加资本金属于什么
  • 权利许可证照印花税优惠政策
  • php主要用于
  • 金蝶利润表主营业务成本公式
  • vue3.0用法
  • 路径规划步骤
  • php使用oci8扩展连接oracle
  • 帝国cms app
  • 企业被吊销后能当被告嘛
  • 营业外支出影响企业利润吗
  • sqlserver2005数据库备份
  • 小规模增值税申报未开票收入怎么填
  • 单位注销合并劳动合同有效吗
  • 商业企业流程图
  • win8 设置打不开
  • windows10玩lol有延迟怎么办
  • win10企业版20h2和1909
  • mac怎么安装安装包
  • centos 安装
  • windows10打开此电脑
  • 寒江孤影原文
  • opengl数据类型
  • 你将会收藏
  • js抓取网页内容
  • shell 数组变量
  • xcopy /i
  • python教程详细
  • 用python写一个学生信息管理系统
  • python爬虫视频教程
  • js处理时间格式
  • jquery easyui 教程
  • python解析excel文档
  • python文件与异常答案
  • 浙江公务员冬令时上班时间
  • 设备租赁增值税怎么抵扣
  • 青岛税务局网上办税厅app
  • 广西税务局热线电话
  • 车辆购置税查询不到应征欠税信息,不能进行扣款操作
  • 平原新区郑州外国语学校
  • 土地增值税的房屋转让指出售 赠与
  • 天津海泰南路属于哪个区
  • 地方税务局几点下班
  • 黑龙江工商局网站官网
  • 辽宁国税征期日历
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设