The Linux tmpwatch command is used to delete files that have not been accessed for a specified period of time.
Linux tmpwatch command Function Description
Use the tmpwatch command to recursively search from a specified directory and delete files that have not been accessed for a specified period of time. This command is typically used to purge directories that are used to temporarily house files (such as /tmp).
tmpwatch ignores symbolic links, it does not switch file systems, and it only removes empty directories and regular files.
Linux tmpwatch Command Syntax
tmpwatch [options] [timeout] [directory]
The meaning of each option in the command is shown in the table.
Option | Description |
---|---|
-a |
Delete files of any type |
-f |
Forced deletion of files or directories |
-q |
The command execution process is not displayed |
-v |
Displays the command execution process in detail |
-t |
Only for testing, not really deleting files or directories |
-m |
Based on the time when the file was modified (mtime) |
-c |
Change time by file (ctime) |
-M |
By folder modified time (mtime) |
-l |
Do not remove symbolic links |
-U <User> |
Exclude files for the specified user |
-x <Path> |
Exclude a specified path |
-X <String> |
Exclude paths that match a string |
-d |
Do not delete an empty directory |
Linux tmpwatch command Examples
Delete files in the /tmp folder that have not been accessed in 3 days
[root@rhel ~]# tmpwatch -afv 3 /tmp