I'm trying to automate some file house keeping I do pretty often. I want to delete all of the files and folders in a directory while excluding the folder "./xfer" and its contents.
I've bee trying to do it using the find command but it is turning out a bit clunky. Is there a better way? I set up my test environment by running:
mkdir test0{1..5}; find . -type d -exec touch '{}'/test-0{1..5} \;
Here is the command I've been working on. Btw I am somewhat new and am mostly doing this as a learning exercise. Also, this would be the last command of a small script I am almost done with.
find /some/directory/path/* -type f ! -path "/some/directory/path/xfer/*" -exec rm -fv {} \;; find /some/directory/path/* -type d ! -path "/some/directory/path/xfer" -exec rm -rfv {} \;