find Overview

The find command is used to locate files by traversing the UNIX tree structure. You can start from any point on the system, even the root level, and traverse through the entire hierarchy. After finding files, you can also perform actions on them.


The general format of the find command is as follows:

						find
						path operators
					

path is the directory in which find will begin a search. operators are one or more of the many find options you specify. The end of this section contains a list of commonly used operators to find. We'll work with several of the most commonly used operators in some of the upcoming examples.

The most common result of find is to produce a list of files. You can produce a list of files in the current working directory, specified by a dot (.), and print those files, as shown in the following example:


# cd /home
#
# ls -l
total 3
drwxr-xr-x   3 col      users        1024 Nov  8 14:09 col
drwxr-xr-x   6 root     root         1024 Nov  8 14:08 ftp
drwxr-xr-x   6 root     root         1024 Nov  8 14:08 httpd
#
# find . -print
.
./httpd
./httpd/apache
./httpd/apache/doc
./httpd/apache/doc/manual.ps.gz
./httpd/cgi-bin
./httpd/cgi-bin/HelpIndex
./httpd/cgi-bin/HelpScreen
./httpd/html
./httpd/html/dt
./httpd/html/dt/dt.html
./httpd/html/dt/dt.html.idx
./httpd/html/dt/dt.index
./httpd/html/dt/expert.gif
./httpd/html/dt/hint.gif
./httpd/html/dt/index.gif
./httpd/html/dt/info2.gif
./httpd/html/dt/note.gif
./httpd/html/dt/sysadm.gif
./httpd/html/dt/up.gif
./httpd/html/dt/warning.gif
./httpd/icons
./ftp
./ftp/bin
./ftp/bin/gzip
./ftp/bin/ls
./ftp/bin/tar
./ftp/bin/zcat
./ftp/etc
./ftp/etc/group
./ftp/etc/passwd
./ftp/lib
./ftp/pub
./col
./col/.bashrc
./col/.cshrc
./col/.login
./col/.profile
./col/lg
./col/lg/lg_layouts
./col/lg/lg_layouts/User
./col/lg/lg3_prefs
./col/lg/lg3_soundPref
./col/lg/lg3_startup

This find operation was performed from the /home directory. Notice that there are only three home directories under /home, and the find command traverses the hierarchy for each of the three home directories. Keep in mind that you probably don't want to perform this find operation at the root level. You will traverse the entire hierarchy and get a list of every file on the system.

When using find, you may discover that you receive a message like the following when a file or directory is encountered for which you do not have adequate permission to traverse:


find: /var/spool/cron: Permission denied

This is not an ucommon message when running find, so don't panic. Users working outside their home directory often encounter this message when running a variety of commands, including find.

A typical find command will specify the path in which to search for a specific file. In this case, the expression is the name of the file for which you wish to search, as shown in the following example:

# find /home -name ftp
/home/ftp

In this example we search the path /home looking for the name ftp.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.42