Assume I remove an rpm as follows:

rpm -e <package-name>

I then do a system wide search:

find / |grep <keyword-from-package-name>

It returns many instances where the keyword was referenced e.g.


If I do the following:

ll /etc/<keyword-from-package-name>

I get the following response:

total 0

Which means the directory is empty, so in the interest of keeping a system tidy:

My question is, what is the recommended way of removing leftover files and directories after removing rpm?

Is it by finding each individual instance and verifying that the file/directory is empty, as described above, and then doing an;

rm -f filename.extension


rm -rf directory_name 

What do you do?

Thank you

  • 1
    What's the problem with leaving an empty directory lying around? In other words, is solving the problem not a waste of resources? – wurtel Sep 27 '18 at 11:55
  • @wurtel Thanks for your response. This may very well be the correct answer, i'm just starting out in my career and was wondering what the more experienced Unix users do. I suppose I assumed that leaving empty directories lying around was/is bad practice. From your answer I assume that an empty directory takes up no system resources, save for some links to the directory name/nodes on the file system tree. – MarkMark Sep 27 '18 at 12:43

The real problem is that the package was not perfectly packaged (as many packages are... sadly): The package installed the /etc/<package> directory but did not own it; so it was not removed upon uninstall. Normally you are not supposed to do any extra actions after removing an rpm.

probably the owner had something like this in his spec file:


which should have been:

  • Thanks, this makes sense, I will look into this I interpret what your saying as: Whoever created the spec file etc... did not include "commands" to ensure the package OWNED each directory it created, therefore when I did rpm - e <package-name> these directories could not be removed as the correct ownership privileges were not present. I plan on investigating the creation of rpms soon, I will definitely keep this in mind when creating them .Thank you – MarkMark Sep 27 '18 at 15:10
  • @MarkMark : I added the concerned spec file parts in my answer – Chris Maes Sep 27 '18 at 15:12
  • Thanks for updating the answer. I did not write the spec file but I do have access it. This is what it contains: %files -f %{EXTRA_FILES} %defattr(-,root,root). EXTRA_FILES is defined at the start of the spec file and when I follow the path it links to I see you are correct as it is a file that contains paths like for example /etc/<package>/* – MarkMark Sep 27 '18 at 16:20
  • Well that means that in extra_files they forgot to add the dir /etc/<package> – Chris Maes Sep 27 '18 at 16:23
  • Correct (see above your last comment) – MarkMark Sep 27 '18 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.