Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer

 
discard

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.