Free Hosting Online for WorkStations

< Previous | Contents | Next >

find – Find Files The Hard Way

While the locate program can find a file based solely on its name, the find program searches a given directory (and its subdirectories) for files based on a variety of at- tributes. We’re going to spend a lot of time with find because it has a lot of interesting features that we will see again and again when we start to cover programming concepts in later chapters.

In its simplest use, find is given one or more names of directories to search. For exam- ple, to produce a list of our home directory:



[me@linuxbox ~]$ find ~

[me@linuxbox ~]$ find ~


On most active user accounts, this will produce a large list. Since the list is sent to stan- dard output, we can pipe the list into other programs. Let’s use wc to count the number of files:



[me@linuxbox ~]$ find ~ | wc -l

47068

[me@linuxbox ~]$ find ~ | wc -l

47068


Wow, we’ve been busy! The beauty of find is that it can be used to identify files that meet specific criteria. It does this through the (slightly strange) application of options, tests, and actions. We’ll look at the tests first.


 

Top OS Cloud Computing at OnWorks: