Linux tmpwatch Command
The Linux tmpwatch command is used to remove temporary files.
Executing the tmpwatch command can delete unnecessary temporary files. You can set the file expiration time in hours.
Syntax
tmpwatch [-afqv][--test][expiration time][directories...]
Parameters:
-a or --all: Delete files of any type.
-f or --force: Forcefully delete files or directories, similar to the "-f" parameter of the rm command.
-q or --quiet: Do not display the command execution process.
-v or --verbose: Display detailed command execution process.
--test: Only test, do not actually delete files or directories.
Example
To remove files in the "/tmp" directory that have not been used for more than one day using the "tmpwatch" command, enter the following command:
$ tmpwatch 24 /tmp/ # Remove files in /tmp directory not used for more than one day
After executing the above command, the result is as follows:
removing directctmp/orbit-tom if not empty
Note: This command requires root privileges. Therefore, you should switch to the root user using the su command before using the tmpwatch command. The switch to root user operation is as follows:
$ su # Switch to root user
Password: ********** # Enter user password