Electric Type

Multimedia

About Us

News

Help

find

find searches through directory trees beginning with each pathname and finds the files that match the specified condition(s). You must specify at least one pathname and one condition.

Structure: find pathname(s) condition(s)

A wise Unix-master friend once told me, "Never forget that in Unix find is your friend." He was right. The find command is useful for searching for particular files, directories, and patterns in your system.

There are several handy conditions you can use to find exactly what you want. The -name condition will find files whose names match a specified pattern. The structure for the name condition is:

find pathname -name pattern

The condition -print will print the matching files to the pathname specified. -print can also be used in conjunction with other conditions to print the output.

If you wanted to find all the files named favorites.html in the directory john_hughes, then you'd do this:

find /john_hughes -name favorites.html -print

This looks through the directory john_hughes and finds all the files in that directory that contain favorites.html, then prints them to the screen. Your output would look like this:

 /john_hughes/sixteen_candles/favorites.html 
/john_hughes/favorites.html 
/john_hughes/breakfast_club/favorites.html 

All meta-characters (!, *, ., etc.) used with -name should be escaped (place a \ before the character) or quoted. Meta-characters come in handy when you are searching for a pattern and only know part of the pattern or need to find several similar patterns. For example, if you are searching for a file that contains the word "favorite," then use the meta-character * to represent matching zero or more of the preceding characters. This will show you all files which contain favorite.

find /john_hughes -name '*favorite*' -print

This looks through the directory john_hughes and finds all the files in that directory that contain the word "favorite." The output would look like this:

 /john_hughes/sixteen_candles/favorites.html
/john_hughes/favorites.html
/john_hughes/least_favorites.html
/john_hughes/breakfast_club/favorites.html
/john_hughes/favorite_line.html

The -user condition finds files belonging to a particular user ID or name. For more conditions, use the online Unix manual.

If you wanted to find all the files in john_hughes that are owned by the user clarence, you would do this:

find /john_hughes -user clarence

Your output would look something like this:

/john_hughes/criminals/judd_nelson.html 
/john_hughes/geeks/anthony_michael_hall.html 

You can also use find to do recursive operations for commands that don't have recursive options. For example, if you want to grep an entire directory tree, you could use find with grep to do this. If you wanted to find all the index files in the john_hughes directory tree, you would type:

 find /john_hughes/ | grep 'index*' 

In this example, you are looking through the john_hughes directory tree for all files named index.

Back to the index.


Tutorials  

User Blogs  

Teaching Tools  

Authoring  

Design  

Programming help  

Advanced Flash  

Javascript  

Glossary  

PHP Coding  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.