How to Use the Unix Find Command

The Unix find command, as the name implies, is a command that you can enter into the command line, or terminal, of a Unix operating system, allowing you to process any given set of files or directories. It is a highly useful command that you can take advantage of on Unix based operating system, making it a valuable tool in a lot of situations.

Using the find command on Unix allows for a multitude of possibilities. The Unix find command can take advantage of many parameters to help you make your search as wide or as narrow as possible. Some examples of the parameters that you can specify are: where to search, the file’s type that you are looking for, what you want to do with the file once it has been found, the actual name of the file, and any logical operators (such as “and” and “or”) that may help expedite your search process.

The commands for each of the above parameters are as follows: pathname is used to define the folders you wish to search in, -type is used to define the file type, -exec is used to show what to do with a file, -name is the name of the file, -a is logical operator “and”, and -o denotes logical operator “or”.

Using the find command is as simple as typing the word “find” into your terminal, followed by whatever parameters you choose. Below is a sample search using the Unix find command when looking for a particular name of a file.

find . -name “filename.mp3″ -print

This command will find the file you are looking for, filename in this case, and print its location on your screen.

A more advanced use of the Unix find command will be much longer and more complex in its code. Below is an example of a much more advanced search.

find /music/oursongs -not ( -name “yoursong.mp3″ -o -name “mysong.mp3″ ) ‘{}’ ; -print

This command will allow you to find a file in the music/oursongs directory that does not include the filenames yoursong.mp3 or mysong.mp3. It will then display all of the found files and their locations on the screen.

Rate this article:

Last updated .

Follow Will.Spencer on