Shell Programming Tmpwatch

Source: Internet
Author: User
Tags add time

As a system administrator, it is often necessary to periodically clean up certain rules of the file, such as expired logs, expired archives, backed up files, and so on.

If you use certain matching rules to find these files and then pass them to the RM command, it's actually a bit of a hassle, so try Tmpwatch.

Tmpwatch

Role:

Delete files that have not been accessed for a certain amount of time.

Parameters:

-U is referenced by the last access time of the file, that is, the last visit time. Can be viewed through ls-lu.

-M according to the last modified time of the file, that is, the last modification time for reference. Can be viewed through ls-l.

-C According to the file-ctime time for reference, CTime update the conditions for writing, change the owner, permissions. Can be viewed through LS-LC.

-x/path exclude a specific directory, that is, the files in that subdirectory are not deleted.

-U user_name excludes files belonging to a specific user, that is, the user's files are not deleted.

-V Displays the delete process. The default is to not show what files were deleted and deleted directly.

--T is used for testing, does not really delete files, can show the process of deleting files.

-D does not delete subdirectories in the file, but files in subdirectories are still deleted.

-F enforces deletion of files that have no write permission on root. Like Root's readonly file.

parameter to add time, default is hours. Some articles say you can use 20d for 20 days, this I have seen, but in rhel5.8, only support hours. You should see the version.

After the time is the directory to check. Multiple directories can be separated by spaces.


After understanding the parameters command, give a typical example

Tmpwatch-m-x/tmp/ceshi1-u oracle-v-T 2/tmp

This command removes files that have not been changed in the/tmp directory for more than two hours and are not part of the Oracle user, excluding files from the/tmp/test1 subdirectory. The entire deletion process is displayed, only tests are done and not deleted.


The Linux system uses this command to periodically clean the/tmp directory.

The following is a look at the/etc/cron.daily/tmpwatch file in rhel5.8.

[Email protected] tmp]# cat/etc/cron.daily/tmpwatch flags=-umc/usr/sbin/tmpwatch "$flags"-x/tmp/. X11-unix-x/tmp/. Xim-unix         -x/tmp/.font-unix-x/tmp/. Ice-unix-x/tmp/. Test-unix-         x '/tmp/hsperfdata_* ' 240/tmp/usr/sbin/tmpwatch "$flags" 720/var/tmpfor D in/var/{cache/man,catman}/{ Cat?,x11r6/cat?,local/cat?}; Do    if [-d ' $d]; then        /usr/sbin/tmpwatch "$flags"-F 720 "$d"    

This is the cleanup rule. Understand the grammar can learn from their own.

Shell Programming Tmpwatch

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.