Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any fast and reliable way to remove everything not related to OS from the server?

In removing everything I mean:

  1. Completely delete all packages and it's dependencies
  2. Completely delete all directories not related to OS

In general I'm interested to do this thing on Debian and CentOS based servers.

If there's no a "fast and reliable" way to do it with one or several commands, then please explain how to do it manually.

share|improve this question
up vote 7 down vote accepted

If you're trying to go back to a clean system, as in "fresh install", you need to do a fresh install. Or if you were prescient enough to bare-metal image the system immediately after install, you could go back to that.

Even with Linux's package systems there are configurations and settings that may not be removed in a remove or uninstall. Especially in a server environment, when you need a clean install you cannot simply remove everything you did since the install. You have to cleanly install to get to a clean install state.

UPDATE: Cleaning packages has some tips for listing packages and cleaning unused packages in a debian system:

To list the installed packages:

dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done | sort -rn > ~/packages.log.txt

He goes on to list methods of listing config files not removed during apt remove processes.

Once you've removed all the packages you wish, run:

apt-get autoremove


apt-get clean

to clean the repositories and unused apt files.

share|improve this answer
I appreciate your help... What's the solution from the solution when you're given root access an virtual server with full of useless stuff? – Otar Feb 7 '12 at 17:43
If this will be just a playground and not a critical system, you can go through and "aptitude purge" for each package you consider useless. But I must reiterate, this is only a usable method if this system is a playground. Even a test system must be standardized. And a virtual server should be really, really, really easy to reinstall a clean OS on. – music2myear Feb 7 '12 at 17:45
Also, once you've removed the detritus, remember to run the various cleanup arguments of aptitude. – music2myear Feb 7 '12 at 17:46
Thank You! I don't think I can get a better answer... :) – Otar Feb 7 '12 at 17:54
Thank you for mentioning my website! – Raymii May 4 '12 at 13:09

If you remove packages one by one since there is no easy way to do so, make sure to "purge" them. That is, if you are in Debian, "aptitude purge packaged" to remove all configuration files. Then there is also "aptitude autoremove" to remove unnecessary dependencies.

share|improve this answer

On Debian, you can use the 'deborphan' tool to list packages that have no packages depending on them, so they often can be removed unless you really know you need them. As with all packaging tools: use with caution.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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