Differences between which, whereis, locate, and find in Linux

Source: Internet
Author: User

In Linux, the difference between which, whereis, locate, and find is that we often look for a file or command in linux, but do not know where it is, you can use the following commands to search. Which view the location of the executable file whereis view the location of the file locate with the database view the location of the file find the actual search hard disk Query file name 1. which Syntax: which executable file name example: [root @ redhat ~] # Which passwd/usr/bin/passwd which searches for executable files in the PATH through PATH environment variables. Therefore, the basic function is to find executable files 2. whereis Syntax: whereis [-bmsu] file or directory name parameter description:-B: only find the binary file-m: only find the file-s in the manual path of the description file: find only source file-u: file without instructions such as: [root @ redhat ~] # Whereis passwd: /usr/bin/passwd/etc/passwd/usr/bin/X11/passwd/usr/share/man/man5/passwd.5.gz/usr/share/man/man1/passwd.1.gz/usr /share/man/man1/passwd.1ssl.gz search out all files related to the passwd file [root @ redhat ~] # Whereis-B passwd:/usr/bin/passwd/etc/passwd/usr/bin/X11/passwd only search the binary file and compare it with find, whereis is very fast, because the linux system records all files in the system in a database file. When whereis and the locate to be introduced below, it searches for data from the database, instead of traversing the hard disk like the find command, and the efficiency is naturally high. However, this database file is not updated in real time. It is updated once a week by default. Therefore, when we use whereis and locate to find the file, we sometimes find the deleted data, you can't find the file you just created because the database file is not updated. 3. locate Syntax: locate file or directory name example: [root @ redhat ~] # Locate passwd/etc/passwd-/etc/cron. daily/passwd/etc/init/passwd. conf/etc/init. d/passwd/etc/pam. d/chpasswd/etc/pam. d/passwd/etc/security/opasswd ............ 4. find Syntax: find path parameter description: Time query parameter:-atime n: list the files that have been retrieved in the memory for n * 24 hours-ctime n: list the files or directories changed or added within n * 24 hours-mtime n: list the files or directories modified within n * 24 hours-newer file: name Search parameters for new files than file:-gid n: Search for files with group ID n-group name: Search for files with group ID n-uid n: search for a file with the owner ID n-user name: find a file with the user name-name file: Find a file with the file name (wildcards can be used) for example: [root @ redhat ~] # Find/-name zgz/home/weblogic/bea/user_projects/domains/zgz/home/oracle/product/10g/export toollogs/ dbca/zgz/home/oracle/product/10g/export toollogs/emca/zgz/home/oracle/oradata/zgz [root @ redhat ~] # Find/-name '* zgz *'/home/zgz/zgz1/home/zgz/zgzdirzgz/home/zgz/zgzdir/home /weblogic/bea/user_projects/domains/zgz/home/weblogic/bea/user_projects/domains/zgz. log00006/home/weblogic/bea/user_projects/domains/zgz. log00002/home/weblogic/bea/user_projects/domains/zgz. log00004/home/weblogic/bea/user_projects/domains/zgz. log/home/weblogic/bea/user_projec Ts/domains/zgz. logstores 8/home/weblogic/bea/user_projects/domains/zgz. log00005 when we use whereis and locate to find the files we need, we can use find, but find is searched through the hard disk, which consumes a lot of hard disk resources, and the efficiency is very low. Therefore, we recommend that you prioritize whereis and locate. Summary: which can only query executable files and aliases (alias). In the PATH variable, whereis can only query binary files (including executable files), instruction documents, and source files, from the linux File database (/var/lib/slocate. db or/var/lib/mlocate. db), so it is possible to find the file you just deleted, or find the new file locate in the database. The database is updated once every day, the file name is partially matched (see the result of 3 locate passwd: opasswd) find is the most powerful and can be searched for anything. Search for files based on conditions and find files on the hard disk, which is very inefficient.

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.