The find command is used to locate files on a Linux or Unix like operating system. The find command will search directory to match the supplied search criteria. You can search for files by type, name, owner, group, date, permissions and more. By default the find will search all subdirectories for you.
Find command basic syntax
The syntax is:
find where-to-look criteria action
find /dir/to/search -name filetosearch
find /dir/to/search -name "*.c"
find /home/nixcraft/project/ -name "*.py" -print
In this example, find will search the /tmp directory for any files named "data*.txt" and display their pathnames:
find /tmp -iname "data*.txt"
OR
cd /tmp find . -iname "data*.txt" -print
Sample outputs:

Fig. 01: Find will show an error message for each directory on which you don't have read permission.
In this above example, I do not have read permission for vmware-root and orbit-Debian-gdm directories. To to avoid this problem try the following syntax:
## redirect error spam to /dev/null ## find where-to-look criteria action 2>/dev/null find . -iname "data*.txt" -print 2>/dev/null
Sample outputs without permission denied spam from find command:
./rtzip/data005.txt ./rtzip/data001.txt ./rtzip/data004.txt ./rtzip/data003.txt ./rtzip/data002.txt ./rtzip/data008.txt ./rtzip/data006.txt ./rtzip/data007.txt ./rtzip/data009.txt
How does it works?
The 2>/dev/null at the end of the find command tells your shell to redirect the error messages (FD #2) to /dev/null, so you don't have to see them on screen. Use /dev/null to to send any unwanted output from program/command. All data written on a /dev/null special file is discarded by the system. To redirect standard error to /dev/null and store file list to output.txt, type:
## redirect error spam to /dev/null ## find . -iname "data*.txt" -print 2>/dev/null > output.txt cat output.txt
See also
- Man page for bash or ksh shell.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 0 comments… add one now }