linux find命令之xargs简单概述
发布时间:2021-03-15 15:37:47 所属栏目:安全 来源:网络整理
导读:在使用 find命令的-exec选项处理匹配到的文件时, find命令将所有匹配到的文件一起传递给exec执行。但有些系统对能够传递给exec的命令长度有限制,这样在find命令运行几分钟之后,就会出现溢出错误。错误信息通常是“参数列太长”或“参数列溢出”。这就是xa
输出: [root@localhost test]# ll 总计 12 drwxr-xr-x 6 root root 4096 10-27 01:58 scf drwxrwxr-x 2 root root 4096 11-13 05:50 test3 drwxrwxr-x 2 root root 4096 11-13 05:50 test4 [root@localhost test]# cd test4 [root@localhost test4]# find . -name "file" | xargs -I [] cp [] .. [root@localhost test4]# ll 总计 304 -rw-r--r-- 1 root root 302108 11-12 22:54 log2012.log -rw-r--r-- 1 root root 61 11-12 22:54 log2013.log -rw-r--r-- 1 root root 0 11-12 22:54 log2014.log [root@localhost test4]# cd .. [root@localhost test]# ll 总计 316 -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log -rw-r--r-- 1 root root 61 11-13 06:03 log2013.log -rw-r--r-- 1 root root 0 11-13 06:03 log2014.log drwxr-xr-x 6 root root 4096 10-27 01:58 scf drwxrwxr-x 2 root root 4096 11-13 05:50 test3 drwxrwxr-x 2 root root 4096 11-13 05:50 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 11-13 06:06 log2015.log [root@localhost test3]# cd .. [root@localhost test]# ll 总计 316 -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log -rw-r--r-- 1 root root 61 11-13 06:03 log2013.log -rw-r--r-- 1 root root 0 11-13 06:03 log2014.log drwxr-xr-x 6 root root 4096 10-27 01:58 scf drwxrwxr-x 2 root root 4096 11-13 06:06 test3 drwxrwxr-x 2 root root 4096 11-13 05:50 test4 [root@localhost test]# cd test3 [root@localhost test3]# find . -name "*.log" | xargs -p -i mv {} .. mv ./log2015.log .. ?...y [root@localhost test3]# ll 总计 0 [root@localhost test3]# cd .. [root@localhost test]# ll 总计 316 -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log -rw-r--r-- 1 root root 61 11-13 06:03 log2013.log -rw-r--r-- 1 root root 0 11-13 06:03 log2014.log -rw-r--r-- 1 root root 0 11-13 06:06 log2015.log drwxr-xr-x 6 root root 4096 10-27 01:58 scf drwxrwxr-x 2 root root 4096 11-13 06:08 test3 drwxrwxr-x 2 root root 4096 11-13 05:50 test4 [root@localhost test]# 说明: -p参数会提示让你确认是否执行后面的命令,y执行,n不执行。 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。 (编辑:青岛站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
站长推荐