Linux uses the locate command to locate a file

Source: Internet
Author: User

Linux uses the locate command to locate a file

From: http://linux-blog.org/finding-files-with-locate/

FIND command

Many Linux users like to use the find command to find files. For example, they usually like this:

Find/-name 'pattern'

Indeed, the powerful function of find is not only used to find files, but also to locate more details, for example, if you want to find some write permissions (if you want to find files which are writable by both their owner and their group) in a directory, you can do this:

Find/-perm-444-perm/222! -Perm/111

Or you want to see the files modified in the last 24 hours under your download directory,

Find/home/user/Downloads/-mtime 0

The find command is not only used to search for files, but also takes time to search for disks. Is there a way to quickly locate it?

LOCATE command

Before using locate, make sure that the mlocate package is installed in the system. Most Linux distributions now integrate this package. If not installed, you can access the mlocate home page (http://carolina.mff.cuni.cz /~ Download and install trmac/blog/mlocate. After the download and installation are successful, you need to execute a command to index your file system. Otherwise, you have to wait until the program is automatically executed.

Run the following command as the root user:

Updatedb &

This command updates your mlocate database in the background, this database contains the index of your file system (This updates the mlocate database that indexes your files and forks it to the background (the '&' forks it to the background ).

After this command is executed, you can easily use the locate command:

Locate firefox | less

This will quickly locate firefox files, directories, and so on. The speed is faster than find, because it reads the index in the mlocate database!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.