Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

I have a directory that has tons of files, and they are named with GUID names.

There are only 3 files in there that I want to keep, and I don't want to move them or anything as the OS might be using them.

How can I delete ALL files in a folder, except for 2 folders and 1 file?

share|improve this question
Select all, hold Ctrl, unselect those that you want to keep, and delete the rest? Or do you want a command line solution? – slhck Oct 30 '11 at 15:11
Ubuntu (or Linux in general) can deal with files that are being moved while they are in use (unless you move them to a different partition). So: mkdir ../tmp ; mv dir1 dir2 file1 ../tmp ; rm * ; mv ../tmp/* . ; rmdir ../tmp. If there are subdirs, make that rm -r *. – ott-- Oct 30 '11 at 16:22
this is on a vps server. – user27449 Oct 30 '11 at 16:49

You must log in to answer this question.

Browse other questions tagged .