Unless you’re superbly organized or have a great memory, chances are you “misplace” files from time to time. Find answers the question, “Now, where did I put that?”
Unless you’re superbly organized or have a great memory, chances are you “misplace” files from time to time. Find answers the question, “Now, where did I put that?”
Of the many file management utilities in Linux, find is worth understanding in depth because it does so much more that just locate files. Find lets you write decision-making logic, specify filters, and run commands on the contents of entire directory trees. Unfortunately, find is not documented well, and its syntax can appear complex. But, as we’ll see, find is actually simple to use, elegant, and a great Linux power tool.
In Search Of…
More on find features soon — first, let’s look at a simple example and some find fundamentals. (If you’ve never used find or want to see more examples, see “Finding Stuff” in the April 2001 issue, or online at http://www.linux-mag.com/2001-04/newbies_01.html.)
The following command looks for all files named foo in the current directory (through the shortcut .) and all of its subdirectories:
The first argument to find is the pathname of the directory where find starts its search. Here we’re using . (dot), the relative path for the current directory. find searches . and all subdirectories within it. For each directory entry (including files, symbolic links, sockets, and “hidden” entries whose names start with a dot, like .mozilla) find performs a test, which is expressed with operators.
Some operators require…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: