3

I have files that fall into two extension categories (.out and .error). Is there a single command that can delete them all at once?

I tried rm -f *.out || *.error but it did not work. Thanks

(i saw the linked post too but am not sure how to deal with multiple extensions still)

Edit: non recursive case

2 Answers2

8

The || is not needed there1, rm will act on all operands, so:

rm *.error *.out

Or, using bash's brace expansion (useful if you have a long list):

rm *.{error,out}

1Not only is || is not needed, it also changes the command structure. || is bash's OR for commands. So, if you had files a.error, b.error, and a.out, b,out, bash would execute:

rm a.out b.out

And if that fails, then execute a.error with b.error as an argument. It won't be passing a.error or b.error to a second run of rm.

muru
  • 207,228
1

The find command is more suitable, especially for zsh,

find . -type f \( -name "*.error" -o -name "*.out" \) -delete
find . -type f \( -name "*.error" -o -name "*.out" \) -exec rm -f {} \;
DawnSong
  • 113