What is the difference between which, Whereis, and locate in Linux commands?

Source: Internet
Author: User

1.find
Find is the most common and powerful lookup command. It can be found in real-time, accurate search, but slow.
Find uses the following format:
#find [Specify directory] [specify condition] [Specify action]
Specify directory: Refers to the directory to be searched and its subdirectories. If not specified, the current directory is assumed to be default.
Specify criteria: Refers to the characteristics of the file you are searching for.
Specify action: Refers to how the results of the search are handled.
Common options:
-name based on file name (strictly case-sensitive, if there are spaces in the middle of a file name, you must enclose the file name in double quotation marks)
-iname Search by file name (case insensitive)
-regex "PATTERN" Regular expression matching
-user Search by file owner
-group Search by file group
-uid lookup based on the UID of the file
-gid based on the user's GID search
-nouser View all files that are not owned by the owner
-nogroup View all files that are not owned by a group
Example: Viewing a file in the TMP directory where the file owner is Redhat
#ls-L ' find/tmp-user redhat '

2.locate
The locate command is not a real-time lookup, so the results of the lookup are inaccurate, but the lookup is fast. Because it does not look for a directory, it is a database (/var/lib/locatedb), which contains all the local file information. The Linux system automatically creates this database and updates it automatically once a day, so you can't find the latest changed files using the Locate command. To avoid this situation, you can manually update the database by using the UpdateDB command before using locate.
Locate using formats
Locate [Specify directory]
Example: Find all files that contain passwd
#locate passwd
Example: Find all files that contain passwd and show only the first 10
#locate-N passwd

3.which
The which command is to find out if a command exists, and where the command is stored.
Example: #which ls

4.whereis
The Whereis command can only be used to search for program names, and only binary files (parameter-B), man description file (parameter-m), and source code file (parameter-s) are searched. If the argument is omitted, all information is returned.
Examples of use of the Whereis command:
#whereis vim
  
5.type
The type command is used to distinguish whether a command is brought by the shell or by a standalone binary file outside the shell. If a command is an external command, then using the-p parameter displays the path to the command, which is equivalent to the which command.
  
#type CD
The system will prompt that the CD is the Shell's own command (build-in).
  
#type grep
The system prompts that grep is an external command and displays the path to the command.
  
#type-P VIM
When you add the-p parameter, it is equivalent to the which command

What is the difference between which, Whereis, and locate in Linux commands?

Related Article

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.