x
Loading
 Loading
Hello, Guest | Login | Register

A Very Valuable Find

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:

$ find . -name foo -print ./junk/foo ./proj/2002/06/foo

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:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. KDE 4.4: Does It Work Yet?
  2. Writing Custom Nagios Plugins with Python
  3. Power Up Linux GUI Apps
  4. Tweeting from the Command Line with Twyt
  5. When Memory Serves You: Using ramfs and tmpfs
Follow Linux Magazine
Rackspace