Monday, December 3, 2012

deleting all files except except one

I came across a situation where i wanted to delete all files and directories in current directory and just leaving one of the files.
You may have other solutions as well. I used xargs for this purpose as:

#ls |grep -v symantec.tar.gz | xargs rm -rf -

It will list all files then do a "grep -v" to filter out a given file. Then piped that output to xargs to delete the files and directories.

No comments:

Post a Comment