会使用xargs的原因是,很多命令其实并不支持管道命令,因此我们可以通过xargs来提供该命令引用standard input之用。
如下:
找出/sbin下面具有特殊权限的文件名,并使用ls -l列出详细属性。
[root@AaronWong shell_test]#
find /sbin/ -perm +7000 | ls -l
总用量 108
-rw-r--r--. 1 root root 1411
4月 27 09:57 backup-04-27-2012.tar.gz
-rw-r--r--. 1 root root
127
4月 25 09:20 li2_1.sh
-rw-r--r--. 1 root root
350
4月 25 09:28 li2_2.sh
-rw-r--r--. 1 root root 1442
4月 25 10:37 li2_3.sh
-rw-r--r--. 1 root root
211
4月 25 19:23 li3_1.sh
-rw-r--r--. 1 root root
757
4月 26 21:02 li3_2.sh
-rw-r--r--. 1 root root
381
4月 26 22:24 li3_3.sh
-rw-r--r--. 1 root root
231
4月 27 09:57 li3_4.sh
-rw-r--r--. 1 root root
315
4月 27 12:49 li4_4_int-or-string.sh
-rw-r--r--. 1 root root
531
4月 28 15:59 li4_5.sh
-rw-r--r--. 1 root root
387
4月 28 16:40 li4_6.sh
-rw-r--r--. 1 root root
80
4月 28 16:46 li4_7_shift.sh
-rw-r--r--. 1 root root
93
4月 28 17:05 li5_1_weirdvars.sh
-rw-r--r--. 1 root root
63
4月 28 19:32 li6_1.sh
-rw-r--r--. 1 root root 1156
4月 30 17:06 li7_1.sh
-rw-r--r--. 1 root root
495
4月 30 17:13 li7_2.sh
-rw-r--r--. 1 root root
217
5月
7 10:29 li7_4_broken-link.sh
-rw-r--r--. 1 root root
38
4月 27 11:12 pym.txt
-rw-r--r--. 1 root root
265
4月 26 21:38 test1.sh
-rw-r--r--. 1 root root
38
4月 25 14:24 test2.sh
-rw-r--r--. 1 root root
83
4月 27 10:23 test3.sh
-rw-r--r--. 1 root root
37
4月 27 12:31 test4.sh
-rw-r--r--. 1 root root
103
4月 28 16:08 test5.sh
-rw-r--r--. 1 root root
28
4月 28 19:18 test6.sh
-rw-r--r--. 1 root root
115
4月 30 17:25 test7.sh
-rwxr--r--. 1 root root
168
4月 26 21:51 uppercase.sh
-rwxr--r--. 1 root root
387
4月 28 16:41 wh
结果竟然仅列出了当前目录pwd下的文件,这不是我们想要的。因为ll(ls)并不是管道命令的原因。
[root@AaronWong shell_test]#
find /sbin/ -perm +7000 | xargs ls -l
-rwsr-xr-x. 1 root root 119808
4月 20 2011 /sbin/mount.nfs
-rwxr-sr-x. 1 root root
6172
2月 26 2011 /sbin/netreport
-rwsr-xr-x. 1 root root
7700 11月
2 2010 /sbin/pam_timestamp_check
-rwsr-xr-x. 1 root root
30704 11月
2 2010 /sbin/unix_chkpwd