<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://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://jackxiang.com/post//</link>
<title><![CDATA[[转]Linux tmp目录自动清理总结]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Wed, 15 May 2019 07:17:21 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp; 在Linux系统中/tmp文件夹下的文件是会被清理、删除的，文件清理的规则是如何设定的呢？ 以Redhat为例，这个主要是因为作业里面会调用tmpwatch命令删除那些一段时间没有访问的文件。<br/><br/>那么什么是tmpwatch呢？其实tmpwatch是一个命令或者说是一个包。如下所示<br/><br/>tmpwatch - removes files which haven’t been accessed for a period of time<br/><br/>[root@DB-Server ~]# rpm -qa &#124; grep tmpwatch<br/>tmpwatch-2.9.7-1.1.el5.5<br/>[root@DB-Server ~]# whereis tmpwatch<br/>tmpwatch: /usr/sbin/tmpwatch /usr/share/man/man8/tmpwatch.8.gz<br/>[root@DB-Server ~]# file /usr/sbin/tmpwatch <br/>/usr/sbin/tmpwatch: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped<br/>[root@DB-Server ~]# <br/><br/>关于tmpwatch命令的参数，不同版本可能有所不同，下面以Red Hat Enterprise Linux Server release 5.7下TMPWATCH(8)为列<br/><br/>作用：<br/><br/>删除一段时间没有被访问的文件。<br/><br/>参数：<br/><br/>-u 按照文件的最后access时间，即最后访问时间为参考。默认选项。可通过ls -lu查看。<br/><br/>-m 按照文件的最后modified时间，即最后修改时间为参考。可通过ls -l查看。<br/><br/>-c 按照文件的-ctime时间做参考，ctime更新的条件为写入、更改属主、权限。可通过ls -lc查看。<br/><br/>-M 按照目录的修改时间来删除目录而不是访问时间。<br/><br/>-a 删除所有类型文件。包括目录和symbolic links<br/><br/>-d --nodirs 排除目录文件，即使是空目录。<br/><br/>-d --nosysmlinks 排除symbolic links类型文件。<br/><br/>-f 强制删除那些root没有写权限的文件。比如root的readonly文件<br/><br/>-q 只报告错误信息。<br/><br/>-x /PATH 排除特定目录，即不删除该子目录里的文件。<br/><br/>-U user_name 排除属于特定用户的文件，即不删除该用户的文件。<br/><br/>-v 显示删除过程。默认是不显示删除了什么文件，直接删除的。<br/><br/>-t 用于测试，并不真正删除文件，能显示出要删除文件的过程。<br/><br/>-d 不删除文件里的子目录，但是子目录里面的文件还是会被删除。<br/><br/> <br/><br/>参数后加时间，默认是hours。也可以使用30d表示30天，但是有些版本只支持hours。 时间后是要检查的目录。可以多个目录用空格分开。如下所示表示720小小时~=30天。<br/><br/>[root@DB-Server ~]#&nbsp;&nbsp;more /etc/cron.daily/tmpwatch<br/>flags=-umc<br/>/usr/sbin/tmpwatch &quot;$flags&quot; -x /tmp/.X11-unix -x /tmp/.XIM-unix &#92;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix &#92;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-X &#039;/tmp/hsperfdata_*&#039; 240 /tmp<br/>/usr/sbin/tmpwatch &quot;$flags&quot; 720 /var/tmp<br/>for d in /var/&#123;cache/man,catman&#125;/&#123;cat?,X11R6/cat?,local/cat?&#125;; do<br/>&nbsp;&nbsp;&nbsp;&nbsp;if [ -d &quot;$d&quot; ]; then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/sbin/tmpwatch &quot;$flags&quot; -f 720 &quot;$d&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fi<br/>done<br/>[root@DB-Server ~]# <br/><br/>如果你想将强制删除30天没有访问的文件改为7天，只需&quot;/usr/sbin/tmpwatch &quot;$flags&quot; 720 /var/tmp&quot;和&quot;/usr/sbin/tmpwatch &quot;$flags&quot; -f 720 &quot;$d&quot; 里面的720改为189即可。<br/><br/>来自：http://www.cnblogs.com/kerrycode/p/5759941.html<br/><br/><br/>==========================实践================================<br/>rpm -qa &#124; grep tmpwatch<br/>tmpwatch-2.9.16-6.el6.x86_64<br/><br/>whereis tmpwatch<br/>tmpwatch: /usr/bin/tmpwatch /usr/sbin/tmpwatch /usr/share/man/man8/tmpwatch.8.gz<br/><br/>cat /etc/cron.daily/tmpwatch<br/>#! /bin/sh<br/>flags=-umc<br/>/usr/sbin/tmpwatch &quot;$flags&quot; -x /tmp/.X11-unix -x /tmp/.XIM-unix &#92;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix &#92;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-X &#039;/tmp/hsperfdata_*&#039; -X &#039;/tmp/.hdb*lock&#039; -X &#039;/tmp/.sapstartsrv*.log&#039; &#92;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-X &#039;/tmp/pymp-*&#039; 10d /tmp<br/>/usr/sbin/tmpwatch &quot;$flags&quot; 30d /var/tmp<br/>for d in /var/&#123;cache/man,catman&#125;/&#123;cat?,X11R6/cat?,local/cat?&#125;; do<br/>&nbsp;&nbsp;&nbsp;&nbsp;if [ -d &quot;$d&quot; ]; then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/sbin/tmpwatch &quot;$flags&quot; -f 30d &quot;$d&quot;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fi<br/>done
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [转]Linux tmp目录自动清理总结]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>