
By default, DNF caches files in the /var/cache/dnf directory. You do not want to manually delete files or directories below /var/cache/dnf. Instead, the dnf clean command can be used to remove files below /var/cache/dnf.
Before using dnf clean, you may want to use the du (disk usage) command to list the size of the /var/cache/dnf directory.
~]$ du -hs /var/cache/dnf
426M /var/cache/dnf
And then use the dnf clean or dnf clean all command to remove files from the /var/cache/dnf directory.
dnf clean all
And then reissue the du (disk usage) command to get the updated size of the /var/cache/dnf directory.
~]$ du -hs /var/cache/dnf
56M /var/cache/dnf
If the size of the /var/cache/dnf directory was not reduced to 0, this typically means you have untracked or disabled repositories, which can be seen with the dnf clean all --verbose command.
~]# dnf clean all --verbose
73 M disabled repos:
73 M /var/cache/yum/x86_64/7Server/rhel-server-rhscl-7-rpms
1.4 M untracked repos:
412 k /var/cache/yum/x86_64/7Server/rhel-7-server-satellite-tools-6.9-rpms
404 k /var/cache/yum/x86_64/7Server/rhel-7-server-satellite-tools-6.5-rpms
396 k /var/cache/yum/x86_64/7Server/rhel-7-server-satellite-tools-6.8-rpms
44 k /var/cache/yum/x86_64/7Server/pe_repo
12 k /var/cache/yum/x86_64/7Server/rhel-7-server-supplementary-rpms
4.0 k other data:
4.0 k /var/cache/yum/x86_64/7Server/timedhosts
74 M total
The dnf clean all command will not remove files from the /var/cache/dnf directory that are mapped to untracked or disabled repositories, thus you may need to use the rm command to remove additional files from the /var/cache/dnf directory.
rm -rf /var/cache/dnf/*
Did you find this article helpful?
If so, consider buying me a coffee over at