Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2691485
  • 博文数量: 505
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 2514
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-23 18:24
文章分类

全部博文(505)

文章存档

2019年(12)

2018年(15)

2017年(1)

2016年(17)

2015年(14)

2014年(93)

2013年(233)

2012年(108)

2011年(1)

2009年(11)

分类: 系统运维

2013-09-29 09:44:31

 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

阅读(1254) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~