Webmonkey
Powered by Atomz.com



Quick Reference:

Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
• Unix Guide
Glossary
Domain Registries

Reference   Unix Guide

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.html files in the john_hughes directory tree, you would type:

 find /john_hughes/ -print |xargs grep '*index.html' 

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

Back to the index.



Feedback  |  Help  |  About Us  |  Contribute  |  Jobs
Advertise  |  Privacy Statement  |  Terms and Conditions

Copyright © 1994-2000 Wired Digital Inc., a Lycos Network site. All rights reserved.