xargs连接前后命令时的功能分析


xargs连接前后命令时的功能分析
 
 xargs的使用:
# find / -type f -name "*.log" -print|xargs  ls  -l #会在执行命令后过段时间才会有输出,即:find完成后结果一块echo给ls 作为输入,只执行了一次ls
# find / -type f -name "*.log" -print|xargs -I{} ls  -l {} #会立即有输出,即:find到一个便会有输出;find的每次结果都作为单次ls的输入即执行了n次ls;
-p参数会提示确认是否执行命令,通过-p参数可以看到上边两个命令的不同。
# find / -type f -name "*.log" -print|xargs -I{} -p  ls  -l {}
ls -l /configassist.log ?...y
-rw-r--r--    1 root     system            0 Jun 27 2012  /configassist.log
ls -l /etc/tunables/lastboot.log ?...y
-rw-r--r--    1 root     system          322 Jun 27 2012  /etc/t*****/lastboot.log
ls -l /home/cft/CFT/distrib/copilot/help_fr/translation cft 2_4.log ?...y
-rw-r--r--    1 cft      ftpgrp        25111 Jan 22 2009  /home/*******/copilot/help_fr/translation cft 2_4.log
ls -l /home/cft/mftlog/cftmonitor.log ?...
# find / -type f -name "*.log" -print|xargs  -p ls  -l        
ls -l /confi****sist.log /etc/tunables/lastboot.log /home/****/copilot/help_fr/translation cft 2_4.log /home/cft/****/cftmonitor.log /home/cft/****/cronclear_20120621.log /home/cft/****/cronclear_20120622.log /home/cft/***/cronclear_20120623.log …………………………………………………… /home/***/dba/dbload/oracle/ctl/tbl_user_inf.log?...
-n可以指定多少个输入执行一次后边的命令,因此当n设为1的时候效果跟-I一样。这样可以解决一些命令的参数需要单个输入的情况。
例子:查看连接8000的光纤卡的属性:
XXXXX:root:/>datapath query adapter |grep fscsi |awk '{print $2}' |xargs -n 1 lsattr -El
attach       switch    How this adapter is CONNECTED         False
dyntrk       yes       Dynamic Tracking of FC Devices        True
fc_err_recov fast_fail FC Fabric Event Error RECOVERY Policy True
scsi_id      0x140c00  Adapter SCSI ID                       False
sw_fc_class  3         FC Class for Fabric                   True
attach       switch    How this adapter is CONNECTED         False
dyntrk       yes       Dynamic Tracking of FC Devices        True
fc_err_recov fast_fail FC Fabric Event Error RECOVERY Policy True
scsi_id      0x20c00   Adapter SCSI ID                       False
sw_fc_class  3         FC Class for Fabric                   True

相关内容

    暂无相关文章