13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 8 ■ USING THE COMMAND LINE BETTER8-4. Using findlocate is a useful tool for quickly finding files. You can manually update the database with sudoupdatedb, although you should use cron to run updatedb regularly for it to be really useful. find issignificantly slower, since it searches the directory tree instead of using a constructed database as withlocate, but it is more reliable since it doesn’t need that database to be up-to-date, and it’s far moreflexible.It can, however, be a little confusing to use at first, especially since its error messages aren’t alwaysvery helpful. This recipe is a quick reference for some of the most helpful find options.The basic usage is as follows:find [-H|-L|-P] [path] [options] [expression]where [path] is the root directory to start the search from and [expression] is the criteria by which youwant to search. Without any other options besides [path], find will keep iterating further into thedirectory from which the search began, until it runs out of subdirectories and files.-H, -L, and -P control how find will deal with symbolic links. -P is the default and sets them to beignored. -L sets them to be followed. -H sets them to be ignored, unless the path given on the commandline is a symbolic link. In this case, the link will be followed. So, if you wanted to start from the directory/local/bin, which was a symlink to /usr/bin, and used this command:find -P /local/bin --name=fooyou would be unsuccessful. Instead, use this:find -H /local/bin --name fooOptionsThe most useful of these is likely to be -maxdepth:find / -maxdepth 2 -name fooThis limits the search to go only two levels below the path given on the command line. So, thiswould find /usr/bin/foo but not /usr/local/bin/foo.-mount is also useful, because it sets find to ignore directories on other filesystems; if you have / and/home on different filesystems, you can search just one or the other. For example, you can use it to checkhow many .bk files you have lying around in the / filesystem but not to look for those in /home:find / -mount -name '*.bk'■ Note If you’re searching an MS-DOS file tree or a CD-ROM, use the -noleaf option to avoid an optimizationthat doesn’t work on these filesystems.179Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!