dnf-clean
Remove DNF cached package data
TLDR
Remove cache files generated from the repository metadata
Mark the repository metadata as expired
Remove repository metadata
Remove any cached packages from the system
Clean up all DNF repository specific metadata and cached files (all of the above)
SYNOPSIS
dnf clean [all|packages|headers|metadata|dbcache|expire-cache|plugins]
PARAMETERS
all
Remove all files from DNF cache directories.
packages
Remove cached RPM packages.
headers
Remove unprocessed RPM header files.
metadata
Remove repository metadata cache.
dbcache
Remove SQLite database cache files.
expire-cache
Mark all repo metadata as expired for refresh.
plugins
Remove plugin-specific cache files.
DESCRIPTION
The dnf clean command is an essential subcommand of the DNF (Dandified YUM) package manager, used in RPM-based distributions like Fedora, RHEL, and CentOS. It removes cached files accumulated from package downloads, metadata fetches, and other operations, helping to reclaim disk space, fix corruption issues, and ensure fresh data.
Caches build up over time: downloaded RPM packages can take gigabytes, metadata describes available packages, headers are RPM previews, dbcache speeds queries, and plugins have their own stores. Running dnf clean targets these selectively or all at once. For example, after updates, cleaning packages frees space without losing repo info. The expire-cache option smartly marks metadata outdated without deletion, triggering refreshes later.
This command boosts performance on space-constrained systems and resolves errors like 'metadata expired' or cache mismatches. It's safe for regular maintenance but use all judiciously to avoid re-downloads. Always run as root via sudo. Combined with dnf update, it keeps systems lean and reliable.
CAVEATS
Use all carefully; it deletes everything, forcing re-downloads later.
expire-cache does not remove files, only marks metadata stale.
Requires root privileges.
EXAMPLES
sudo dnf clean all - Wipe all caches.
sudo dnf clean packages - Remove downloaded RPMs.
sudo dnf clean metadata - Force metadata refresh.
HISTORY
DNF, developed by Fedora Project and RPM Fusion, succeeded YUM. Preview in Fedora 18 (2013), default in Fedora 22 (2015). dnf clean mirrors and improves YUM's clean for better cache management.


