Finding Files Using locate and find


You can use both the find and locate commands to search the file system for files matching certain criteria. The locate command uses a database describing the known files on your system. The locate database is built and updated automatically as long as your system is running at the appropriate time. By default on Mac OS X and Mac OS X Server systems, the locate database is updated at 4:30 a.m. each Saturday. You can execute the script that updates the locate database using the command sudo /etc/weekly.

The locate command understands the wildcard characters that the shell uses (wildcards are discussed later in this appendix). To pass the wildcard character on to the locate command, you must escape the character so that the shell doesn't process it. For example, the command locate `*.rtf' or locate \*.rtf will print a list of all files with names ending in .rtf, while locate *.rtf results in an error.

The command find ~ -name *.rtf print starts a search of the files in the user's home directory and prints on the screen all of the files with names ending in lowercase .rtf, while the command find ~ -iname *.rtf print starts a search of the files in your home folder and lists all of the files with names ending in .rtf, regardless of whether the rtf is in lowercase or uppercase.

File Locations

Mac OS X introduces a number of predefined folders intended to contain files of particular types. Since many applications depend on the name and location of these folders, they should not be renamed or moved.

Most applications in the Mac OS X graphical user interface (GUI) reside in /Applications, and operating system files reside in /System. By convention, UNIX programs store their configuration information in /etc while most command-line tools are installed in /bin, /sbin, /usr/bin, or /usr/sbin. Shells search these four folders to find the programs whose names you enter on the command line. Programs in other locations may be executed by specifying an absolute or relative path to the executable.

For example, /Developer/Tools/GetFileInfo /Users executes the GetFileInfo command installed by the developer tools. The current folder is not part of the default search path on Mac OS X. This is important for Windows users, but it is a security risk to have a shell include the current folder in the search path, because it could allow unauthorized applications to execute.




Apple Training Series. Mac OS X System Administration Reference, Volume 1
Apple Training Series: Mac OS X System Administration Reference, Volume 1
ISBN: 032136984X
EAN: 2147483647
Year: 2005
Pages: 258
Authors: Schoun Regan

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net