0

I usually delete empty files and folders in my home directory with find using the following command:

find /home/tjuh -empty -delete

However I would like to exlcude one folder, namely /home/tjuh/.local/share/Steam/steamapps/common/ so I tried:

find . -not -path '/home/tjuh/.local/share/Steam/steamapps/common/' -empty

to see if that specific folder is excluded from the search but it's not really working the way I want it to.

Any suggestions?

4

The -path argument is a pattern, so you have to use wildcards, or it will only match exact:

find . -not -path "./.local/share/Steam/steamapps/common/*" -empty

Also, you have to use absolute or relative paths, not mix them. The above one is with relative paths, this one is with absolute paths:

find /home/tjuh -not -path "/home/tjuh/.local/share/Steam/steamapps/common/*" -empty
0

Try:

rm `find /home/tjuh -empty | grep -v "^/home/tjuh/.local/share/Steam/steamapps/common/"`
0

If you want to exclude that directory and all its descendents, then -prune is what you need:

find "$HOME" -path "$HOME/.local/share/Steam/steamapps/common" -prune -o -empty -delete

This means: if the path matches $HOME/.local/share/Steam/steamapps/common then -prune (ignore it and its children) and continue, OR if -empty then -delete (and continue).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.