I have a folder with a few files in it; I like to keep my folder clean of any stray files that can end up in it. Such stray files may include automatically generated backup files or log files, but could be a simple as someone accidentally saving to the wrong folder (my folder).
Rather then have to pick through all this all the time I would like to know if I can create a batch file that only keeps a number of specified files (by name and location) but deletes anything not on the “list”.
[edit] Sorry when I first saw the question I read
bashinstead ofbatch. I don’t delete the not so useful answer since as was pointed out in the comments it could be done with cygwin.You can list the files, exclude the one you want to keep with grep and the submit them to rm.
If all the files are in one directory:
or in a directory tree
where
~/.list_of_files_to_excludeis a file with the list of patterns to exclude (one per line)Before testing it make a backup copy and substitute
rmwithechoto see if the output is really what you want.