Книга: Fedora™ Unleashed, 2008 edition
Finding Files from an Index with locate
Finding Files from an Index with locate
When you use the find
command, it searches recursively through each directory each time you request a file. This is slow, as you can imagine. Fortunately, Fedora ships with a cron
job that creates an index of all the files on your system every night. Searching this index is extremely fast, which means that, if the file you are looking for has been around since the last index, this is the preferable way of searching.
To look for a file in your index, use the command locate
followed by the names of the files you want to find, like this:
$ locate myfile.txt
On a relatively modern computer (1.5GHz or higher), locate
should be able to return all the matching files in less than a second. The trade-off for this speed is lack of flexibility. You can search for matching filenames, but, unlike with find
, you cannot search for sizes, owners, access permissions, or other attributes. The one thing you can change is case sensitivity; use the -i
parameter to do a search that is not case sensitive.
Although Fedora rebuilds the filename index nightly, you can force a rebuild whenever you want by running the command updatedb
as root. This usually takes a few minutes, but when it's done the new database is immediately available.
- Printing the Contents of a File with cat
- Changing Directories with cd
- Changing File Access Permissions with chmod
- Copying Files with cp
- Printing Disk Use with du
- Finding Files by Searching with find
- Searches for a String in Input with grep
- Paging Through Output with less
- Creating Links Between Files with ln
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Reading Manual Pages with man
- Making Directories with mkdir
- Moving Files with mv
- Listing Processes with ps
- Deleting Files and Directories with rm
- Printing the Last Lines of a File with tail
- Printing Resource Usage with top
- Printing the Location of a Command with which
- Copying Files
- Basic Commands
- Changing File Access Permissions with chmod
- Copying Files with cp
- Making Directories with mkdir
- Moving Files with mv
- Deleting Files and Directories with rm
- 13.2.3 Finding Free Blocks Quickly
- Database Files
- Инструкция INSERT INTO ... FROM ... UNION ...
- Index
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces