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

I need to make a daily cleanup in a download directory.

I have saw this question and tested the answer

rm !("test 1"|"test 4")

It work great, but require to have cd to the directory before. Since my app need to be two direcltory higher in many part, I d like to don t have to make something like

cd /app/download
rm !("test 1"|"test 4")
cd ../..

I have tried

rm !("./app/download/test 1"|"./app/download/test 4")

But well, it delete the content of the higher directory, not download/

share|improve this question
up vote 2 down vote accepted

You were almost there:

shopt -s extglob   # ← Only needed if you haven't enabled it yet
rm ./app/download/!("test 1"|"test 4")

The !(…) will be expanded with the full path to all files except the ones in !(…). Since you prefix the arguments to rm with the path ./app/download/, no other files higher than that directory will be deleted.

share|improve this answer
It work like a charms, thanks you. – DrakaSAN Sep 19 '13 at 8:30

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.