系统之家 - 系统光盘下载网站!

当前位置:系统之家 > 系统教程 > Linux find命令与xargs组合使用

Linux find命令与xargs组合使用的方法(3)

时间:2014-12-31 17:57:43 作者:qipeng 来源:系统之家 1. 扫描二维码随时看资讯 2. 请使用手机浏览器访问: https://m.xitongzhijia.net/xtjc/20141231/33885.html 手机查看 评论

  实例6:使用xargs执行mv

  命令:

  代码如下:

  find 。 -name “*.log” | xargs -i mv {} test4

  输出:

  代码如下:

  [root@localhost test]# ll

  总计 316

  -rw-r--r-- 1 root root 302108 11-03 06:19 log2012.log

  -rw-r--r-- 1 root root 61 11-12 22:44 log2013.log

  -rw-r--r-- 1 root root 0 11-12 22:25 log2014.log

  drwxr-xr-x 6 root root 4096 10-27 01:58 scf

  drwxrwxr-x 2 root root 4096 11-12 22:54 test3

  drwxrwxr-x 2 root root 4096 11-12 19:32 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

  总计 12drwxr-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]# 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]#

  实例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 -f

  rm -f

  [root@pdtest4]#

  说明:

  -l1是一次处理一个;-t是处理之前打印出命令

  实例8:使用-i参数默认的前面输出用{}代替,-I参数可以指定其他代替字符,如例子中的[]

  命令:

  输出:

  代码如下:

  [root@localhost test]# ll

  总计 12drwxr-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]#

发表评论

0

没有更多评论了

评论就这些咯,让大家也知道你的独特见解

立即评论

以上留言仅代表用户个人观点,不代表系统之家立场

其他版本软件

热门教程

人气教程排行

Linux系统推荐

官方交流群 软件收录