Differences between find, locate, whereis, which, and type commands in linux

Source: Internet
Author: User
Differences among find, locate, whereis, which, and type commands in linux: 1. findwww.2cto. the comJava code find is the most common and powerful search command. you can use it to find any file you want. Different from querying database (/var/lib/locatedb) files, find... differences among find, locate, whereis, which, and type commands in linux: 1. find www.2cto.com Java code find is the most common and powerful search command. you can use it to find any file you want. Unlike the query database (/var/lib/locatedb) file, find uses the following format to find the disk space: $ find <指定目录> <指定条件> <指定动作> - <指定目录> : The directory to be searched and all its subdirectories. The current directory is used by default. - <指定条件> : The features of the file to be searched. - <指定动作> : Specific processing of search results. Www.2cto.com If no parameter is added, find searches for the current directory and its subdirectories by default, does not filter any results (that is, returns all files), and displays them all on the screen. Example of using find: $ find.-name 'My * 'searches for all files whose names start with my in the current directory (including subdirectories, the same as below. $ Find.-name 'My * '-ls searches the current directory for all files whose names start with my and displays their details. $ Find.-type f-mmin-10 search for all common files updated in the current directory in the past 10 minutes. If the-type f parameter is not added, search for common files + special files + directories. 2. the locate Java code locate command is actually another method of "find-name", but it is much faster than the latter because it does not search for a specific directory, instead, search for a database (/var/lib/locatedb) that contains information about all local files. The Linux system automatically creates the database and updates the database once a day. Therefore, the latest changed files cannot be found using the locate command. To avoid this problem, you can use the updatedb command to manually update the database before using locate. Use instance of the locate command: $ locate/etc/sh to search for all files starting with sh in The etc directory. $ Locate ~ /M searches all files starting with m in the user's home directory. $ Locate-I ~ /M searches all files starting with m in the user's home directory, and ignores the case. 3. the whereis Java code whereis command can only be used for program name search, and only searches for binary files (parameter-B), man description files (parameter-m), and source code files (parameter-s ). If the parameter is omitted, all information is returned. Like locate, the instance used to query the whereis command in the database (/var/lib/locatedb) File: $ whereis grep 4. the which Java code which command searches for the location of a system command in the PATH specified by the PATH variable and returns the first search result. That is to say, by using the which command, you can see whether a system command exists and where the command is executed. Use instance of the which command: $ which grep 5. the type Java code type command is actually not a search command. it is used to distinguish whether a command is provided by shell or by an independent binary file outside shell. If a command is an external command, use the-p parameter to display the path of the command, which is equivalent to the which command. Example of using the www.2cto.com type command: $ type cd system will prompt that cd is a built-in shell command (build-in ). $ Type grep system prompts that grep is an external command and displays the path of this command. After $ type-p grep is added with the-p parameter, it is equivalent to the which command.
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.