0% found this document useful (0 votes)
58 views

Linux "Find" Command

The find command searches directories and subdirectories for files that match search criteria. It allows searching by file name, owner, group, type, permissions, and date. By default, find will print the names of any matching files found in the current directory and below. Various criteria like -name can be used along with paths to search to locate specific files on the system in a recursive manner.

Uploaded by

bkjklb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as EHTML, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Linux "Find" Command

The find command searches directories and subdirectories for files that match search criteria. It allows searching by file name, owner, group, type, permissions, and date. By default, find will print the names of any matching files found in the current directory and below. Various criteria like -name can be used along with paths to search to locate specific files on the system in a recursive manner.

Uploaded by

bkjklb
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as EHTML, PDF, TXT or read online on Scribd
You are on page 1/ 1

LINUX "FIND" COMMAND

The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files that match the supplied search criteria. You can search for files by name, owner, group, type, permissions, date, and other criteria. The search is recursive in that it will search all subdirectories too. The syntax looks like this:
find where-to-look criteria what-to-do

All arguments to find are optional, and there are defaults for all parts. (This may depend on which version of find is used. Here we discuss the freely available Gnu version of find, which is the version available on YborStudent.) For example, where-to-look defaults to . (that is, the current working directory), criteria defaults to none (that is, select all files), and what-to-do (known as the find action) defaults to print (that is, display the names of found files to standard output). Technically, the criteria and actions are all known as find primaries. For example:
find

will display the pathnames of all files in the current directory and all subdirectories. The commands
find . -print find -print find .

do the exact same thing. Here's an example find command using a search criterion and the default action:
find / -name foo

This will search the whole system for any files named foo and display their pathnames. Here we are using the criterion -name with the argument foo to tell find to perform a name search for the filename foo. The output might look like this:
/home/wpollock/foo /home/ua02/foo /tmp/foo

If find doesn't locate any matching files, it produces no output. The above example said to search the whole system, by specifying the root directory (/) to search. If you don't run this command as root, find will display a error message for each directory on which you don't have read permission. This can be a lot of messages, and the matching files that are found may scroll right off your screen. A good way to deal with this problem is to redirect the error messages so you don't have to see them at all:
find / -name foo 2>/dev/null

You can specify as many places to search as you wish:


find /tmp /var/tmp . $HOME -name foo

You might also like