<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>https://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>https://jackxiang.com/post//</link>
<title><![CDATA[[实践Ok]find exec 接合rm -Rf 删除文件和拷备文件的小应用脚本。 ]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Fri, 13 Mar 2015 06:11:41 +0000</pubDate> 
<guid>https://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	将目录中的文件查找出来并全部拷备文件到指定目录:<br/>find&nbsp;&nbsp;. -type f -exec cp -rf &#123;&#125; /tmp/pdf &#92;;<br/><br/>背景：删除一些vim的临时文件及批量文件修改时间，有用xargs的也有用exec......但是这个命令的后面这一部分得小心点写，有一个空格。<br/>第一：花括号&#125;后面必须得有空格.<br/>第二：最后斜杠后面必须得有分号。<br/>第三：exec前面有一个中横线，否则也不行，三者必须要注意。<br/><textarea name="code" class="C" rows="15" cols="100">
find . -ctime -1 -exec ls -l&nbsp;&nbsp;&#123;&#125; &#92;;
find /data/bak/redis/6403 -ctime +60 -exec rm -Rf &#123;&#125; &#92;;&nbsp;&nbsp;
59 23 * * * find /var/log -name &quot;*&quot; -exec bash -c &quot;echo &quot;&quot; &gt; &#123;&#125;&quot; &#92;;
</textarea><br/><br/><br/>如：<br/>#!/bin/bash<br/>Redisdb_file=/data/redis/6403/redis.rdb<br/>Redisbak_dir=/data/bak/redis/6403<br/>Bak_time=`date +%Y%m%d%H%M`<br/>mkdir -p $Redisbak_dir<br/>/bin/cp -rf $Redisdb_file $Redisbak_dir/redis.rdb.$Bak_time<br/>find $Redisbak_dir -name &quot;redis.db.201*&quot; -mtime +30 -exec rm -rf &#123;&#125; &#92;;<br/><br/>+ /bin/cp -rf /data/redis/6403/redis.rdb /data/bak/redis/6403/redis.rdb.201610262250<br/>+ find /data/bak/redis/6403 -name &#039;redis.db.201*&#039; -mtime +30 -exec rm -rf &#039;&#123;&#125;&#039; &#039;;&#039;<br/>-----------------------------------------------------------------------------------------------------------------------------------<br/>[root@iZ25dcp92ckZ jackxiang.com]# find . -name &quot;*.php&quot; -exec grep &quot;messagebox-bottom&quot; &#123;&#125; &#92;;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;messagebox-bottom&quot;&gt;<br/>&nbsp;&nbsp;&lt;div class=&quot;messagebox-bottom&quot;&gt;&lt;a href=&quot;javascript: window.history.back();&quot;&gt;&#123;$lnc[263]&#125;&lt;/a&gt; &#124; &lt;a href=&quot;index.php&quot;&gt;&#123;$lnc[88]&#125;&lt;/a&gt; &#123;admin_plus&#125;&lt;/div&gt;<br/>&nbsp;&nbsp;&lt;div class=&quot;messagebox-bottom&quot;&gt;&lt;a href=&quot;javascript: window.history.back();&quot;&gt;&#123;$lnc[263]&#125;&lt;/a&gt; &#124; &lt;a href=&quot;index.php&quot;&gt;&#123;$lnc[88]&#125;&lt;/a&gt; &#123;admin_plus&#125;&lt;/div&gt;<br/><br/><br/>[root@iZ25dcp92ckZ jackxiang.com]# find . -name &quot;*.php&quot; -exec grep -lr -A3 &quot;您目前的用户组是&quot; &#123;&#125; &#92;;<br/>./lang/zh-cn/common.php<br/><br/>======================这儿不得不说xargs和-exec的区别=================================<br/>1）-exec里的&#123;&#125; 相当于一个变量，于是grep时是每次针对单个文件的，所以没有文件名显示。<br/>2）而xagrs是管道，则grep认为是一堆文件进行grep，于是默认就有文件名。<br/><textarea name="code" class="php" rows="15" cols="100">
[root@iZ25dcp92ckZ jackxiang.com]# find . -name &quot;*.php&quot; -exec&nbsp;&nbsp;grep -rin &quot;autojump&quot; &#123;&#125; &#92;;
443:function catcherror ($error, $enableautojump=true) &#123;
449:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$t-&gt;showtips($lnc[4], $error, &quot;&#123;$lnc[5]&#125;&#124;&lt;&quot;, $enableautojump);
137:&nbsp;&nbsp;&nbsp;&nbsp;function showtips($title, $tips, $links=&#039;&#039;, $enableautojump=false) &#123;
147:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($enableautojump) $tips.=&quot;&lt;br/&gt;&#123;$lnc[310]&#125;&lt;ul&gt;&quot;;
156:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
164:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
169:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($enableautojump) $csslocation.=$autojump;
</textarea><br/><textarea name="code" class="php" rows="15" cols="100">
[root@iZ25dcp92ckZ jackxiang.com]# find . -name &quot;*.php&quot; &#124;xargs grep -rin &quot;autojump&quot; 
./global.php:443:function catcherror ($error, $enableautojump=true) &#123;
./global.php:449:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $t-&gt;showtips($lnc[4], $error, &quot;&#123;$lnc[5]&#125;&#124;&lt;&quot;, $enableautojump);
./inc/boblog_class_run.php:137: function showtips($title, $tips, $links=&#039;&#039;, $enableautojump=false) &#123;
./inc/boblog_class_run.php:147:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($enableautojump) $tips.=&quot;&lt;br/&gt;&#123;$lnc[310]&#125;&lt;ul&gt;&quot;;
./inc/boblog_class_run.php:156:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
./inc/boblog_class_run.php:164:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
./inc/boblog_class_run.php:169:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($enableautojump) $csslocation.=$autojump;
</textarea><br/>-exec就像这样指定了文件名，当然没有文件名存在了，在使用时根据实际情况进行使用：<br/><textarea name="code" class="php" rows="15" cols="100">
[root@iZ25dcp92ckZ jackxiang.com]# grep -rin &quot;autojump&quot;&nbsp;&nbsp;./inc/boblog_class_run.php
137:&nbsp;&nbsp;&nbsp;&nbsp;function showtips($title, $tips, $links=&#039;&#039;, $enableautojump=false) &#123;
147:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($enableautojump) $tips.=&quot;&lt;br/&gt;&#123;$lnc[310]&#125;&lt;ul&gt;&quot;;
156:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
164:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$autojump=&quot;&lt;meta http-equiv=&#92;&quot;refresh&#92;&quot; content=&#92;&quot;3; url=&#123;$current_link[1]&#125;&#92;&quot; /&gt;&quot;;
169:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($enableautojump) $csslocation.=$autojump;
</textarea><br/>=======================================================================================<br/><br/><br/><br/><br/><br/><br/><br/><br/>下面这两种情况都是没法执行得到的，如下：<br/>[root@localhost test]# find . -ctime -1 -exec ls -l&nbsp;&nbsp;&#123;&#125; &#92; ;<br/>find: missing argument to `-exec&#039;<br/><br/>[root@localhost test]# find . -ctime -1 -exec ls -l&nbsp;&nbsp;&#123;&#125; &#92;<br/>&gt; <br/><br/>所以，必须得要注意，而用xargs来做这个就不用那么多事了：<br/>find . -mtime +30 &#124; xargs rm -f<br/>每天运行一次，清理半月外的文件，予以删除：<br/><textarea name="code" class="php" rows="15" cols="100">
0 0 * * * /usr/bin/find /data/upload/temp -ctime +15 -exec rm -Rf &#123;&#125; &#92;;
0 0 * * * /usr/bin/find /data/upload/dest -ctime +15 -exec rm -Rf &#123;&#125; &#92;;
</textarea><br/>==================================<br/>[root@localhost ~]# find /tmp -type f&nbsp;&nbsp;&nbsp;&nbsp;<br/>/tmp/.X0-lock<br/>/tmp/test.pcap<br/>[root@localhost ~]# find /tmp -type f&#124;xargs echo<br/>/tmp/.X0-lock /tmp/test.pcap<br/><br/><br/>exec选项后面跟随着所要执行的命令或脚本，然后是一对儿&#123; &#125;，一个空格和一个&#92;，最后是一个分号。<br/><br/>[root@localhost ~]# find /tmp -type f -exec ls -l &#123;&#125; &#92;;<br/>-r--r--r-- 1 root root 11 Aug 21&nbsp;&nbsp;2014 /tmp/.X0-lock<br/>-rw-r--r-- 1 root root 24 Mar 10 10:42 /tmp/test.pcap<br/>[root@localhost ~]# find /tmp -type f -exec ls -l &#123;&#125; ; <br/>find: missing argument to `-exec&#039;<br/>[root@localhost ~]# find /tmp -type f -exec ls -l &#123;&#125; &#92;;<br/>-r--r--r-- 1 root root 11 Aug 21&nbsp;&nbsp;2014 /tmp/.X0-lock<br/>-rw-r--r-- 1 root root 24 Mar 10 10:42 /tmp/test.pcap<br/><br/><br/><br/>应用 一：<br/>&nbsp;&nbsp;使用功能：删除当前目录下所有的后缀为&#039;~&#039;的文件<br/>&nbsp;&nbsp;使用场合：VI编辑时经常产生~备份文件，当备份文件时候，特别是生成patch时候，需要将它删掉，否则产生很多垃圾数据，但单个删除太慢，以下为整体删除<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/>&nbsp;&nbsp;find ./ -name &#92;*~ -exec rm -rfv &#92;&#123;&#92;&#125; &#92;;<br/><br/>应用 二：<br/>&nbsp;&nbsp;使用功能：将当前目录所有的文件的时间更新为当前时间<br/>&nbsp;&nbsp;使用场合：在嵌入式开发时运行虚拟机器，当windows的时间提前于虚拟机时，则windiows编辑的文件不能在虚拟下正常编译，提示时间太新，这时需同步时间<br/><br/>&nbsp;&nbsp;find ./ -name &#92;* -exec touch &#92;&#123;&#92;&#125; &#92;;<br/><br/>find -exec 介绍<br/>1. find -exec command &#123;&#125; +&nbsp;&nbsp;将所用的符合规的文件一起执行一次command 命令<br/>&nbsp;&nbsp;例：<br/>&nbsp;&nbsp;&nbsp;&nbsp;touch 1ww 2ww 3ww 4ww<br/>&nbsp;&nbsp;&nbsp;&nbsp;mkdir 123<br/>&nbsp;&nbsp;&nbsp;&nbsp;touch 123/4ww<br/>&nbsp;&nbsp;&nbsp;&nbsp;touch 123/5ww<br/><br/>&nbsp;&nbsp;find ./ -name &#92;*ww -exec ls -l&nbsp;&nbsp;&#92;&#123;&#92;&#125; +&nbsp;&nbsp;<br/>&nbsp;&nbsp;实际最后执行以下命令：<br/>&nbsp;&nbsp;ls -l 1ww 2ww 3ww 4ww 123/4ww<br/><br/> 2.&nbsp;&nbsp; find&nbsp;&nbsp;-exec command &#123;&#125; ;&nbsp;&nbsp;对符合规则的文件单独执行command命令<br/>&nbsp;&nbsp;find ./ -name &#92;*ww -exec ls -l&nbsp;&nbsp;&#92;&#123;&#92;&#125; &#92;;&nbsp;&nbsp;<br/>&nbsp;&nbsp;实际最后执行以下命令：<br/>&nbsp;&nbsp;ls -l 1ww <br/>&nbsp;&nbsp;ls -l 2ww<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ls -l 3ww <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ls -l 4ww<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ls -l 123/4ww<br/>&nbsp;&nbsp;ls -l 123/5ww<br/><br/>&nbsp;&nbsp;3.&nbsp;&nbsp;find&nbsp;&nbsp;-execdir command &#123;&#125; +&nbsp;&nbsp;&#039;+&#039; &#039;;&#039;同上，只是execdir所运行的文件在其文件的当前目录(可消除竞争)<br/>&nbsp;&nbsp;find ./ -name &#92;*ww -execdir ls -l&nbsp;&nbsp;&#92;&#123;&#92;&#125; +<br/>&nbsp;&nbsp;实际最后执行以下命令&nbsp;&nbsp;<br/>&nbsp;&nbsp;ls -l 1ww 2ww 3ww 4ww <br/>&nbsp;&nbsp;pwd ./123<br/>&nbsp;&nbsp;ls -l 4ww 5ww <br/><br/>&nbsp;&nbsp;4.&nbsp;&nbsp; find ./ -name &#92;*ww -execdir ls -l&nbsp;&nbsp;&#92;&#123;&#92;&#125; &#92;;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;ls -l 1ww<br/>&nbsp;&nbsp;ls -l 2ww<br/>&nbsp;&nbsp;ls -l 3ww<br/>&nbsp;&nbsp;ls -l 4ww<br/>&nbsp;&nbsp;pwd ./123<br/>&nbsp;&nbsp;ls -l 4ww <br/>&nbsp;&nbsp;ls -l 5ww&nbsp;&nbsp; <br/>&nbsp;&nbsp;<br/><br/><br/>摘自：http://www.cnblogs.com/peida/archive/2012/11/14/2769248.html
]]>
</description>
</item><item>
<link>https://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践Ok]find exec 接合rm -Rf 删除文件和拷备文件的小应用脚本。 ]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>