<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[常用命令]xargs的i参数]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Wed, 10 Jul 2013 11:51:34 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;xargs与find经常结合来进行文件操作，平时删日志的时候只是习惯的去删除，比如 # find . -type f -name &quot;*.log&quot; &#124; xargs rm -rf *就将以log结尾的文件删除了，如果我想去移动或者复制就需要使用参数来代替了。 xargs&nbsp;&nbsp;-i 参数或者-I参数配合&#123;&#125;即可进行文件的操作。 -I replace-str<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Replace&nbsp;&nbsp;occurrences&nbsp;&nbsp;of&nbsp;&nbsp;replace-str&nbsp;&nbsp;in the initial-arguments with names read from standard input.&nbsp;&nbsp;Also, unquoted blanks do not terminate<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;input items; instead the separator is the newline character.&nbsp;&nbsp;Implies -x and -L 1.<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --replace[=replace-str], -i[replace-str]<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This option is a synonym for -Ireplace-str if replace-str is specified, and for -I&#123;&#125; otherwise.&nbsp;&nbsp;This option is deprecated; use -I&nbsp;&nbsp;instead.<br/>man了一下看的还是不太懂，通过例子，做作实验将我的理解写一下。 ############### 操作的目录下的文件###############[root@test05 ab]# ls<br/>1kk.zip&nbsp;&nbsp;3kk.zip&nbsp;&nbsp;5kk.zip&nbsp;&nbsp;b.rar&nbsp;&nbsp;d.rar&nbsp;&nbsp;f.rar&nbsp;&nbsp;h.rar&nbsp;&nbsp;j.rar&nbsp;&nbsp;mini.txt&nbsp;&nbsp;ni.txt<br/>2kk.zip&nbsp;&nbsp;4kk.zip&nbsp;&nbsp;a.rar&nbsp;&nbsp;&nbsp;&nbsp;c.rar&nbsp;&nbsp;e.rar&nbsp;&nbsp;g.rar&nbsp;&nbsp;i.rar&nbsp;&nbsp;k.rar&nbsp;&nbsp;nii.txt###################使用 i 参数 ##################<br/>[root@test05 ab]# find . -type f -name &quot;*.txt&quot; &#124; xargs -i cp &#123;&#125;&nbsp;&nbsp;/tmp/k/<br/>[root@test05 ab]# ls ../k/<br/>mini.txt&nbsp;&nbsp;nii.txt&nbsp;&nbsp;ni.txt<br/>[root@test05 ab]# ###################&nbsp;&nbsp;使用 I&nbsp;&nbsp;参数 ################<br/>[root@test05 ab]# find . -type f -name &quot;*.txt&quot; &#124; xargs -I &#123;&#125; cp &#123;&#125;&nbsp;&nbsp;/tmp/n/<br/>[root@test05 ab]# ls ../n/<br/>mini.txt&nbsp;&nbsp;nii.txt&nbsp;&nbsp;ni.txt 结果出来了，&nbsp;&nbsp;加-i 参数直接用 &#123;&#125;就能代替管道之前的标准输出的内容； 加 -I 参数 需要事先指定替换字符<br/><br/>来自：<br/>http://hi.baidu.com/xmflycat/item/359efb2dbc490799b6326358<br/>---------------------------------------------------------------------------------------------------------------------<br/>如下实践，更容易理解：<br/><textarea name="code" class="php" rows="15" cols="100">
root@192.168.137.128:~/xargs# touch a.txt b.txt c.txt
root@192.168.137.128:~/xargs# ls
a.txt&nbsp;&nbsp;b.txt&nbsp;&nbsp;c.txt
root@192.168.137.128:~/xargs# find . -type f -name &quot;*.txt&quot; &#124; xargs -i cp &#123;&#125;&nbsp;&nbsp;/tmp/k/
cp: 无法创建普通文件&quot;/tmp/k/&quot;: 是一个目录
cp: 无法创建普通文件&quot;/tmp/k/&quot;: 是一个目录
cp: 无法创建普通文件&quot;/tmp/k/&quot;: 是一个目录
root@192.168.137.128:~/xargs# mkdir /tmp/k/
root@192.168.137.128:~/xargs# find . -type f -name &quot;*.txt&quot; &#124; xargs -i cp &#123;&#125;&nbsp;&nbsp;/tmp/k/
root@192.168.137.128:~/xargs# ls /tmp/k/
a.txt&nbsp;&nbsp;b.txt&nbsp;&nbsp;c.txt
root@192.168.137.128:~/xargs#&nbsp;&nbsp;find . -type f -name &quot;*.txt&quot; &#124; xargs -I &#123;&#125; cp &#123;&#125;&nbsp;&nbsp;/tmp/n/
cp: 无法创建普通文件&quot;/tmp/n/&quot;: 是一个目录
cp: 无法创建普通文件&quot;/tmp/n/&quot;: 是一个目录
cp: 无法创建普通文件&quot;/tmp/n/&quot;: 是一个目录
root@192.168.137.128:~/xargs# mkdir /tmp/n
root@192.168.137.128:~/xargs#&nbsp;&nbsp;find . -type f -name &quot;*.txt&quot; &#124; xargs -I &#123;&#125; cp &#123;&#125;&nbsp;&nbsp;/tmp/n/
root@192.168.137.128:~/xargs# ls /tmp/n/
a.txt&nbsp;&nbsp;b.txt&nbsp;&nbsp;c.txt
</textarea>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [常用命令]xargs的i参数]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>