fpurge - Linux
Overview
fpurge is a command-line utility used to purge a file system of stale files and directories, freeing up disk space. It identifies and deletes files based on their access and modification times, as well as their size and name patterns.
Syntax
fpurge [-a] [-d] [-f] [-i] [-m] [-n] [-N] [-o] [-p] [-r] [-s] [-t] [-T] [-u] [-x] <path>...
Options/Flags
-a Purge archives and compressed files.
-d Purge directories.
-f Force deletion without prompting for confirmation.
-i Interactive mode; prompts before deleting each file or directory.
-m Purge only files with modification time older than specified value. Format: YYYY-MM-DD HH:MM:SS
.
-n Dry run mode; displays files and directories that would be purged without actually deleting them.
-N Exclude files and directories matching the specified wildcard pattern.
-o Purge only files and directories smaller than specified size in bytes.
-p Purge only files and directories that match the specified wildcard pattern.
-r Recursively purge directories.
-s Purge symbolic links.
-t Purge files with access time older than specified value. Format: YYYY-MM-DD HH:MM:SS
.
-T Exclude files and directories modified within the specified timeframe. Format: DAYS_BACK
.
-u Purge files not owned by the current user.
-x Print a summary of the files and directories purged.
Examples
Purge all files in the current directory older than 30 days:
fpurge -m "$(date -d 'now - 30 days' +%Y-%m-%d %H:%M:%S)"
Purge all empty directories in the "/tmp" directory:
fpurge -d -r /tmp
Purge all files in the "/home" directory with the extension ".bak":
fpurge -p "*.bak" /home
Dry run purge in the "/var" directory:
fpurge -n /var
Common Issues
- File permission errors: Ensure that you have sufficient permissions to delete the files and directories.
- Missing time values: Use the current system time if no specific time value is provided.
- Incorrect date or time format: Follow the specified format (YYYY-MM-DD HH:MM:SS) for time-based parameters.
- Empty directory not purged: Use the
-s
flag to purge symbolic links to empty directories.
Integration
Combine with find
for advanced purging:
find / -name "*.tmp" -mtime +30 | xargs fpurge -f
Use with cron
for scheduled purging:
0 0 * * * fpurge -m "$(date -d 'now - 60 days' +%Y-%m-%d %H:%M:%S)" /var
Related Commands
du
– Display disk usage statistics.df
– Display disk space usage.rm
– Delete files and directories.