Searching Files

July 26, 2002, 12:00 AM —  ITworld — 

The "find" command enables you to find a file based on its name, type,
owner, creation time, size, group, and other criteria. The find command
looks as follows:

find directory -option criteria

Searching by Name
To locate a file by its name, use the -name option. For example, the
following command locates a file called report in the forecast
directory:

$find forecast -name report

The -print option instructs find to display the file(s) it locates and
their paths on the standard output. For example:

$find summer -name july_report.dat -print
summer/july_report.dat

If you specify an absolute path in the command, find will display
absolute paths, too:

$find /home/jane/summer -name july_report.dat -print
/home/jane/summer/july_report.dat

The special characters . and .. represent your current working directory
and its parent directory, respectively. To locate a file called
invoices.txt in the current directory and display the results on the
screen, type:

$find . -name invoices.txt -print
./invoices.txt

Searching by Type
The -type option enables you to locate a file according to its type.
-type takes a single character that specifies the file type as follows:

Symbol Meaning
b block device file
c character device file
d directory file
f regular file
p named pipe
l symbolic link

For example, to find the directory customers located under the /home
directory, type:

$find /home -name customers -type d -print
/home/letters/customers

Miscellaneous Criteria
You can locate files according to their size by using the -size option.
For example, to find a file whose size is 3 blocks, type:

$find customers -size 3

To specify a file's size in bytes rather than blocks, append the letter
'c' to the size value:

$find /home -size 2048c

To locate a file by its group, use the -group option:

$find /home -name outline -group developers

To locate all the files created during the last 15 minutes in the
current directory, use the -mmin option like this:

$find -mmin +0 -mmin -15

To find files that have been modified within the last two days, type:

$find -mtime -2

Wildcards
You may use shell wildcards as a filename. The following command locates
all the files that have a .h extension under the directory sources:

$find sources -name '*.h'

You must quote the filename when using wildcards. Otherwise, the shell
would attempt to evaluate the filename before passing it to the command.

» posted by ITworld staff

ITworld

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.

Webcast

Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.

White Paper

Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.

Free stuff

Crimeware: Understanding New Attacks and Defenses
By Markus Jakobsson, Zulfikar Ramzan
Published Apr 6, 2008 by Addison-Wesley Professional. Part of the Symantec Press series.
Enter now! | Official rules | Sample chapter

Securing VoIP Networks: Threats, Vulnerabilities, and Countermeasures
By Peter Thermos, Ari Takanen
Published Aug 1, 2007 by Addison-Wesley Professional.
Enter now! | Official rules | Sample chapter

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources