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'm on Linux, using Bash.

I need to remove all files without a certain suffix, for example "dist". I know there are some tricks to do it, rather than removing all the unwanted files one by one.

share|improve this question

Use the following to list all the files that would be removed (just to be sure):

find /path/to/directory -mindepth 1 ! -name "*dist"

Add -type f if you only want to delete regular files, not symbolic links or directories.


Run the command with additional -delete argument at the end to remove them.

share|improve this answer
    
@slhck Thanks, don't know what I was thinking (probably not much) – Daniel Beck Nov 15 '11 at 11:23

If you have extended globbing enabled, you can try:

rm !(*.dist)

Note: if you have directories without the .dist extension, this will will try and delete them too, but will fail.

To turn on extended globbing use: shopt -s extglob

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .