The tmpwatch
command recursively deletes files that have not been accessed within a given period of time. It is commonly used to clean up directories used for temporary storage and can be used to set file expiration times, with the default unit being hours.
tmpwatch [-u | -m | -c] [-MUadfqstvx] [--verbose] [--force] [--all] [--nodirs] [--nosymlinks] [--test] [--fuser] [--quiet] [--atime | --mtime | --ctime] [--dirmtime] [--exclude path ] [--exclude-user user ] time dirs
-a, --all
: Delete all types of files, not just regular files, symbolic links, and directories.-c, --ctime
: Decide to delete files based on the file'sctime
(i.e.,inode
change time) instead ofatime
, and for directories, make the decision based onmtime
.-d, --nodirs
: Do not attempt to delete directories even if they are empty.-f, --force
: Delete files even ifroot
does not have write access, similar torm -f
.-l, --nosymlinks
: Do not attempt to delete symbolic links.-m, --mtime
: Decide to delete files based on the file'smtime
(i.e., modification time) instead ofatime
.-M, --dirmtime
: Decide to delete directories based on the directory'smtime
instead ofatime
, completely ignoring directory time.-q, --quiet
: Report only fatal errors.-s, --fuser
: Try to use thefuser
command to see if files are open before deleting them. By default, this is not enabled, but it can be helpful in some cases.-t, --test
: Do not delete files but take the actions to delete them. This implies-v
.-u, --atime
: Decide to delete files based on the file's access time, which is the default value. Note that regularupdatedb
filesystem scans will retain recent directory times.-U, --exclude-user=user
: Do not delete files owned by a specific user. The user can be a username or a numerical userID
.-v, --verbose
: Print detailed information, with two levels of verbosity available.-x, --exclude=path
: Skip the specified path. If thepath
is a directory, all files within it will also be skipped. If the path does not exist, it must be an absolute path that does not contain symbolic links.-X, --exclude-pattern=pattern
: Skip paths matching a specific pattern. If a directory matches thepattern
, all the files within it will also be skipped. The pattern must match an absolute path that does not contain symbolic links.
To remove files in the /var/log/
directory that have not been accessed in over 30
days:
tmpwatch 30d /var/log/
List all files in the /tmp/
cache directory that have been idle for at least 30
hours:
tmpwatch –mtime 30 –nodirs /tmp/ –test
Delete all files in the /tmp/
cache directory that have not been accessed for at least 30
hours:
tmpwatch -am 30 –nodirs /tmp/
https://github.com/WindrunnerMax/EveryDay
https://linux.die.net/man/8/tmpwatch
https://www.runoob.com/linux/linux-comm-tmpwatch.html
https://www.interserver.net/tips/kb/tmpwatch-command-linux/
-a, --all
: Deletes all files, not just regular files, symbolic links, and directories.-c, --ctime
: Determines the deletion of files based on thectime
orinode
change time rather thanatime
, and for directories based onmtime
.-d, --nodirs
: Do not attempt to delete even if the directory is empty.-f, --force
: Deletes files even ifroot
does not have write access, similar torm -f
.-l, --nosymlinks
: Do not attempt to delete symbolic links.-m, --mtime
: Determines the deletion of files based on themtime
or modification time rather thanatime
.-M, --dirmtime
: Determines the deletion of directories based on the directory'smtime
or modification time, completely ignoring directory time.-q, --quiet
: Report only fatal errors.-s, --fuser
: Attempts to use thefuser
command to check if the file is open before deleting it, not enabled by default, but helpful in some cases.-t, --test
: Does not delete files, but performs the actions to delete them, meaning-v
.-u, --atime
: Determines the deletion of files based on their access time, which is the default, note that periodicupdatedb
file system scans will preserve recent directory times.-U, --exclude-user=user
: Do not delete files owned by a specific user, the user can be a username or a numerical userID
.-v, --verbose
: Print detailed output, with two levels of verbosity available.-x, --exclude=path
: Skip the path, ifpath
is a directory, all files within it will also be skipped, if the path does not exist, it must be an absolute path that does not include symbolic links.-X, --exclude-pattern=pattern
: Skip paths that match the pattern, if a directory matches thepattern
, all the files within it will be skipped, the pattern must match an absolute path that does not include symbolic links.
To delete files older than 30d
that have not been accessed in the /var/log/
log directory.
tmpwatch 30d /var/log/
List all files in the /tmp/
cache directory that have not been modified for at least 30
hours.
tmpwatch –mtime 30 –nodirs /tmp/ –test
Delete all files in the /tmp/
cache directory that have not been accessed for at least 30
hours.
tmpwatch -am 30 –nodirs /tmp/
https://github.com/WindrunnerMax/EveryDay
https://linux.die.net/man/8/tmpwatch
https://www.runoob.com/linux/linux-comm-tmpwatch.html
https://www.interserver.net/tips/kb/tmpwatch-command-linux/