Unix find command exclude files command

Fig.01: Linux find command exclude files command

Fig.01: Linux find command exclude files command

You can use the find command but exclude files or directories using the following simple syntax:

## Find all all python (*.py) files but exclude prod directory to search ##
find . -type f -name "*.py" ! -path "./prod/*" 
## OR ##
find $HOME/projects/scripts/ -type f -name "*.py" ! -path "$HOME/projects/scripts/prod/*" -print
## OR ##
find $HOME/projects/scripts/ -type f -name "*.py" ! -path "$HOME/projects/scripts/prod/*" -ls

In this example find all perl files on unix but exclude /usr/, /home/, and /etc/ directories:
find / -type f -name "*.py" ! -path "/usr/*" ! -path "./home/*" ! -path "/etc/*" -print
find / -type f -name "*.py" ! -path "/usr/*" ! -path "/home/*" ! -path "/etc/*" -ls
## Skip /usr/ and /home/ directory while search all .py files ##
find / -type f -name "*.py" ! -path "/usr/*" ! -path "/home/*" ! -ls

Sample outputs:

11931230    4 -rw-r--r--   1 root     root          155 Apr 11  2014 /etc/python3.4/sitecustomize.py
11931229    4 -rw-r--r--   1 root     root          155 Mar 22  2014 /etc/python2.7/sitecustomize.py

Examples and usage: Find command: Exclude or Ignore Files (e.g. Ignore All Hidden .dot Files )