Monday, April 17, 2017
Delete all files in directroy except
Delete all files in directroy except
You have multiple options to achieve this. If you want to delete all the files in a directory except the ones that start with the letter "a", the simplest option is to use:
rm [!a]*But if you want to delete everything except the files that contain "to_keep" in their names you can use greps inverse matching capability like this:
rm $(ls * | grep -v to_keep)
If what youre looking for is to delete every file except a particular one named "my_file" the previous option might not work for you because it wont delete any file that contains "my_file" as part of their filenames. The following will ensure that this doesnt happen:
rm $(ls * | grep -v ^my_file$)
download more info
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment