Finding files and file listing
The find
command is one of the great utilities in the Unix/Linux command-line toolbox. It is useful both at the command line and in shell scripts. Like cat
and ls
, find
has many features, and most people do not use it to its fullest. This recipe deals with some common ways to utilize find
to locate files.
Getting ready
The find
command uses the following strategy: find
descends through a hierarchy of files, matches files that meet the specified criteria, and performs some actions. The default action is to print the names of files and folders, which can be specified with the -print
option.
How to do it...
To list all the files and folders descending from a given directory, use this syntax:
$ find base_path
The base_path
can be any location from which find
should start descending (for example, /home/slynux/
).
Here's an example of this command:
$ find . -print .history Downloads Downloads/tcl.fossil Downloads/chapter2.doc …
The .
specifies the current directory and ....