ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

xargs和find

2021-10-18 17:03:10  阅读:139  来源: 互联网

标签:tmp xargs Oct sh root find localhost


[root@localhost shell]# cat /tmp/xargs
1 2 3
4 5 6 7 8
9 10

[root@localhost shell]# cat /tmp/xargs |xargs
1 2 3 4 5 6 7 8 9 10
[root@localhost shell]# cat /tmp/xargs |xargs -n 3    #-n参数为划分为多行
1 2 3
4 5 6
7 8 9
10
[root@localhost shell]#

 

xargs   -d选项为输入指定一个定界符,默认是空格

[root@localhost shell]# echo "pwdAcatAtreeABC" |xargs -d A
pwd cat tree BC

[root@localhost shell]# echo "pwdAcatAtreeABC" |xargs -d A -n 2
pwd cat
tree BC

 

 结合find和xargs

[root@localhost tmp]# ll
total 20
drwxr-xr-x. 2 root root 6 Oct 2 13:49 consul-test
drwxr-xr-x. 3 root root 18 Oct 6 16:06 data
drwxr-xr-x. 2 root root 6 Oct 6 15:47 data1
d-wx-wx-wx. 2 root root 6 Oct 6 15:48 data2
-rw-r--r--. 1 root root 25 Oct 18 09:03 nusers.sh
drwx------. 3 root root 17 Oct 14 10:25 systemd-private-7cacc66a24ab427a83d19076e73213b6-httpd.service-d9KtA4
drwxr-xr-x. 2 root root 6 Oct 6 15:46 test
-rw-r--r--. 1 root root 89 Oct 18 11:40 total-1.sh
-rw-r--r--. 1 root root 91 Oct 18 13:26 total-2.sh
-rw-r--r--. 1 root root 82 Oct 18 11:08 total.sh
-rw-r--r--. 1 root root 22 Oct 18 16:15 xargs
[root@localhost tmp]# find /tmp -type f name "*.sh"
find: paths must precede expression: name
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
[root@localhost tmp]# find /tmp -type f -name "*.sh"
/tmp/nusers.sh
/tmp/total.sh
/tmp/total-1.sh
/tmp/total-2.sh
[root@localhost tmp]# find . -type f -name "*.sh"
./nusers.sh
./total.sh
./total-1.sh
./total-2.sh

[root@localhost tmp]# find . -type f -name "*.sh" -print0 | xargs -0
./nusers.sh ./total.sh ./total-1.sh ./total-2.sh
[root@localhost tmp]# find . -type f -name "*.sh" -print0 | xargs -0 rm -f     #用find匹配出/tmp目录下.sh文件,然后用xargs将这些删除
[root@localhost tmp]# ll
total 4
drwxr-xr-x. 2 root root 6 Oct 2 13:49 consul-test
drwxr-xr-x. 3 root root 18 Oct 6 16:06 data
drwxr-xr-x. 2 root root 6 Oct 6 15:47 data1
d-wx-wx-wx. 2 root root 6 Oct 6 15:48 data2
drwx------. 3 root root 17 Oct 14 10:25 systemd-private-7cacc66a24ab427a83d19076e73213b6-httpd.service-d9KtA4
drwxr-xr-x. 2 root root 6 Oct 6 15:46 test
-rw-r--r--. 1 root root 22 Oct 18 16:15 xargs
[root@localhost tmp]#

 

 

 

标签:tmp,xargs,Oct,sh,root,find,localhost
来源: https://www.cnblogs.com/liutaolt/p/15421279.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有