|
|
Unix Commands
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)
find 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 sweets, then you'd do this:
find /sweets -name favorites.html -print
This looks through the directory sweets and finds all the files in that directory that contain favorites.html, then prints them to the screen.
Your output would look like this:
/sweets/hard_candies/favorites.html
/sweets/favorites.html
/sweets/soft_candies/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 /sweets -name '*favorite*' -print
This looks through the directory sweets and finds all the files in that directory that contain the word "favorite."
The output would look like this:
/sweets/hard_candies/favorites.html
/sweets/favorites.html
/sweets/least_favorites.html
/sweets/soft_candies/favorites.html
/sweets/favorite_flavors.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 sweets that are owned by the user george, you would do this:
find /sweets -user george
Your output would look something like this:
/sweets/storage/refridgeration.html
/sweets/baking/sweetrolls.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 sweets directory tree, you would type:
find /sweets/ -print |xargs grep '*index.html'
In this example, you are looking through the sweets directory tree for all files named index.
Back to Unix Commands
|
|
- Account Log ins
Control Panel Sample
- Getting Started
Chosing a Password
FTP
Index Files
Quick Html
Virus Tracker
Anti Spam Tips
- Creating Databases
Moving Databases
- Htaccess
Hot Linking
Password Protection
- Unix Commands
Chmod
Find
Grep
Ls
Regular Expressions
Telnet / SSH
|