Bootstrap FreeKB - Linux Commands - find command - exclude directories from search (-not -path)
Linux Commands - find command - exclude directories from search (-not -path)

Updated:   |  Linux Commands articles

If you are not familiar with the find command, check out our Getting Started article.

Let's say you want to search below /opt but you do not want to find files or directories in the /opt/foo and /opt/bar directories. 

The -not -path options can be used to exclude directories from the search. For example, the following command will exclude /opt/tmp and /opt/user from the search.

find /opt -not \( -path /opt/foo -prune \) -not \( -path /opt/bar -prune \)

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 472454 in the box below so that we can be sure you are a human.