This is “find” command tutorial.
The command find will search location you specify for files that match the supplied search criteria.
The search is recursive which means that find will search the location that you specify and all the subdirectories that it find in there.
If you type
# find –help
You’ll see the help text which starts by listing:
Usage: find [path...] [expression]
Default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions.
To simplify it, look at it like this.
find path criteria action
Examples:
# find / -name httpd
Will located any file or folder named httpd searching recursivley from the root path and downwards.
Depending on your configuration, that might take a while since you are searching the whole OS installation.
On my Cent OS server the output looks like.
/var/log/httpd
/var/lock/subsys/httpd
/usr/include/httpd
/usr/lib/httpd
/usr/sbin/httpd
/etc/logrotate.d/httpd
/etc/rc.d/init.d/httpd
/etc/sysconfig/httpd
/etc/httpd
Please note that if find doesn’t locate any matching files, there will be no output.
You also will see an error message on each directory that you don’t have access permissions to.
You can specify as many places as you want to search in, for example:
# find /var $HOME /bin -name history
This will search /var, your home directory and /bin for files name history.
You can use wildcards in the file name argument.
# find / -name mail\*log
This will search the whole system for any file with a name that begins with mail and ends with log.
Another way of specifying wildcards in your search is
# find / -name ‘*.log’
This will find all the files in your system that have the .log extension.
If you want to find more than one type of files, use the following:
# find / -name ‘*.log’ -o -name ‘*.pid’
This will find all the log and pid files on your system.
To find a list of the directories, use the -type specifier. Here’s an example:
# find . -type d
This is a basic tutorial, as find is very customizable and powerful command.
Please refer to the full usage of find by typing.
# man find
In your shell.