Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of tmpwatch Command under Linux

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the usage of tmpwatch command under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the usage of the tmpwatch command under Linux.

Tmpwatch

Delete files that have not been accessed for a recent period of time in hours, saving disk space. Tmpwatch recursively deletes files that are not accessed at a given time. Typically, it is used to clean up directories that are used to temporarily save spaces, such as / tmp. When changing a directory, tmpwatch is very sensitive to possible race conditions and exits if an error is detected. It does not follow the symbolic links in the directory it is cleaning (even if a symbolic link is given as its parameter), it does not switch file systems, skips the root user's lost+found directory, and deletes only empty directories, regular files, and symbolic links.

By default, tmpwatch determines the date of a file based on its atime (access time), not their Mtime (modification time). If files are not removed when "ls-l" implies that they should be deleted, use "ls-u" to check their data to determine if this explains the cause of the problem.

If the-- atime ","-- ctime "or"-- mtime "options are specified, the time to delete files is determined by the maximum of them. If the"-- dirmtime "option means ignoring the directory's atime, even if the"-atime "option is used.

The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Tmpwatch [options] time file

Tmpwatch [- u |-m |-c] [- MUadfqstvx] [--verbose] [--force] [--all] [--nodirs] [--nosymlinks] [--test] [--quiet] [--atime |-- mtime |-- ctime] [--dirmtime] [--exclude path] [--exclude-user user] time dirs

2. List of options

Option

Description

-u |-- atime

The decision to delete the file is made based on the atime (access time) of the file. Note that periodically updated file system scans keep directories up to date.

-m |-- mtime

The decision to delete the file is made based on the file's Mtime (modification time) rather than the atime.

-c |-ctime

Delete a file based on its ctime (Inode Changing Time) rather than atime; for directories, make a decision based on mtime

-M |-- dirmtime

Make the decision to delete the directory based on the Mtime (modification time) of the directory rather than atime; completely ignore the atime of the directory

-a |-all

Delete all file types, not just regular files, symbolic links, and directories.

-d |-- nodirs

Do not try to delete directories, even if they are empty.

-f |-force

Forced deletion, even if root users do not have the right to write

-l |-- nosymlinks

Do not delete symbolic links

-Q |-- quite

Only fatal errors are reported

-s |-- fuser

Try to use the "fuser" command to see if the file is open before deleting it. It is not enabled by default. It does help in some cases, but not all. Depends on the fuser installed in / sbin. HPUX or Solaris is not supported

-t |-- test

Don't delete, just demonstrate what to do.

-U |-- exclude-user=user

Do not delete the file of the specified owner, you can specify either the user name or the user ID

-v |-- verbose

Show details

-x |-- exclude

Skip the directory and its internal files, and if the path does not exist, it must be an absolute path that does not contain symbolic links.

-X |-- exclude-pattern=pattern

Skip the path matching pattern; if the directory matches the pattern, all files contained in it will also be skipped. Patterns must match absolute paths that do not contain symbolic links.

3. Examples

1) Delete files that have not been accessed in the current directory within 1 hour

[root@192 weijie] # ls

1.c 2.c 3.c magic.mgc test01 test03 wjtpflR

1.c2.c3.cmy.iso test02 wj234.q1C

You have new mail in / var/spool/mail/root

[root@192 weijie] # tmpwatch 1.

[root@192 weijie] # ls

1.c 1.c ~ 2.c

2) do not delete the files of the specified user

[root@192 weijie] # ll

Total dosage 12

-rwxr--r-- 1 root david 12 September 13 16:49 1.c / / the file is owned by root

-rw-r--r-- 1 root david 30 September 13 16:43 1.c ~

-rwxr--r-- 1 root root 11 September 13 16:52 2.c

[root@192 weijie] # tmpwatch-U root 1. / / do not delete files of root users

[root@192 weijie] # ls

1.c 1.c ~ 2.c

A Linux learning platform has been made, and a prototype has come out at present, which you can refer to and use.

Link: https://pan.baidu.com/s/1GOLVU2CbpBNGtunztVpaCQ password: n7bk

At this point, I believe you have a deeper understanding of "the use of the tmpwatch command under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report