Does "rm" command has a option "--exclude"?
hi,
Does "rm" command has a option "--exclude"? I need to delete a butch of files exclude some files with .txt extension. thanks! jimmy |
there's no --exclude option (see man page), though rm takes a list of arguments, so you can so something like:
rm `ls | grep -v 'txt$'` -or- rm `find . -type f | grep -v 'txt$'` .. if you want to do it recursively. ... as with anything that deletes files permanently, use with caution. |
great, thanks!
|
Another way of selecting files is using find with exec rm, something like
Code:
find /home/jimyjiang -name "IMG_*.JPG" -exec rm {} + |
Yet another way, if your shell is bash and extglob is enabled (I'm sure other shells have things like it and more) is to do something like
Code:
rm PATH/!(*.txt) On the find, to follow along with b0uncer and to get closer to what you were asking, you could do Code:
find . -type f ! -name '*.txt' -execdir rm {} + Doesn't much matter, as you have your problem solved but it might be useful to others with similar issues. |
Just wanted to add that I never knew you could throw a 'not' into the find command. Cool!
|
All times are GMT -5. The time now is 04:03 PM. |