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?


3 Answers 3


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

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).



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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .