Unix Shell find/xargs

// Solaris

 

1. find ./ -name "*.jar" -exec jar -tvf {} /;

 

For each file found from 'find' command, it will invoke a new process space to run 'tar -tvf ...'.

 

 

2. find ./ -name "*.jar" | xargs jar -tvf

把find的输出结果, 分批送给'jar -tvf' 执行

如果find出来两个文件(lib/a.jar, lib/b.jar), 那么上述命令相当于 jar -tvf lib/a.jar lib/b.jar

 

3. find ./ -name "*.jar" | xargs -t -I {} jar -tvf {}

    find ./ -name "*.jar" | xargs -t -I {} mv {} {}.bak

    -t 选项指示 xargs 先打印命令,然后再执行。

    -i 选项告诉 xargs 用每项的名称替换 {}

 

 

     // -I 每一行的输出都要执行jar的命令, 即每个发现的文件执行一次。

     -I replstr  Insert mode. utility is  executed  for  each
                     line  from standard input, taking the entire
                     line as a single argument, inserting  it  in
                     argument s for each occurrence of replstr. A
                     maximum of five arguments in  arguments  can
                     each   contain  one  or  more  instances  of
                     replstr. Any blank characters at the  begin-
                     ning  of  each line are ignored. Constructed
                     arguments cannot grow larger than 255 bytes.
                     Option  -x  is  forced  on.  The  -I  and -i
                     options are mutually exclusive; the last one
                     specified takes effect.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值