rm [!a]*But if you want to delete everything except the files that contain "to_keep" in their names you can use grep's inverse matching capability like this:
rm $(ls * | grep -v to_keep)
If what you're looking for is to delete every file except a particular one named "my_file" the previous option might not work for you because it won't delete any file that contains "my_file" as part of their filenames. The following will ensure that this doesn't happen:
rm $(ls * | grep -v '^my_file$')
No comments:
Post a Comment