The following command will remove all files and folders in the current directory, except for those mentioned.
find . -mindepth 1 ! -path '*testResults*' ! -path '*artifacts*' ! -path '*node_modules*' -exec rm -r {} + 2>/dev/null
My question is: how to also exclude the .git hidden folder from getting deleted?
Use ! -name '.git'
:
find . -mindepth 1 ! -path '*testResults*' ... ! -name '.git' ...
The fact that you use ! -path
but don't know about ! -name
shows that you just pick some random stuff from the internet instead of looking at the right place of information: The man page! So just go ahead and type:
man find