Possible Duplicate:
How to delete all files in a directory except some?
How to delete all but one(or some) file in Unix ?
Something like
rm -rf -ignore myfile.txt *
How to delete all but one(or some) file in Unix ? Something like
|
|||
|
|
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Example :
To remove all files except 'test2' :
Then 'ls' output is :
EDIT: Thanks for the comment. If the directory contains some files with spaces :
You can use (with bash) :
'ls' output :
|
|||||||||
|
|
Assuming you're using the bash shell (the most common case), you can use the negation globbing (pathname expansion) symbol:
This uses extended globbing, so you would need to enable this first:
|
|||
|
|
|
This page gives a variety of options depending on the shell: http://www.unix.com/unix-dummies-questions-answers/51400-how-remove-all-except-one-file.html |
|||
|
|
|
For a recursive |
|||
|
|