Five search commands for Linux: Find,locate,whereis,which,type__linux

Source: Internet
Author: User

Turn from: http://www.kuqin.com/linux/20091009/70532.html

Recently, I was learning Linux, here are some notes.

When you use a computer, you often need to find files.

There are many ways to do this in Linux. Foreign website Linuxhaxor summed up five commands, you can see yourself know a few. Most programmers, who are likely to use 2 to 3 of them frequently, have few people who are familiar with these 5 commands.

1. Find

Find is the most common and powerful search command you can use to find any file you're looking for.

Find uses the following format:

  $ find < Specify directory > < specify conditions > < specify action >

-< Specify directory: the directory to search for and all of its subdirectories. The current directory is assumed by default.

-< Specify conditions: The characteristics of the file to search for.

-< Specify action: Perform specific processing of search results.

If nothing is added, find defaults to search the current directory and its subdirectories, and does not filter any results (that is, all files are returned) and displays them all on the screen.

Use example of Find:

  $ find.-name "my*"

Searches the current directory (with subdirectories, below) for all file names starting with my.

  $ find.-name "my*"-ls

Searches the current directory for all files whose filenames start with my, and displays their details.

  $ find.-type f-mmin-10

Searches the current directory for all normal files that have been updated in the last 10 minutes. If you do not add the-type f parameter, search for normal files + special files + directories.

2. Locate

The locate command is another way of writing "Find-name", but it is much faster than the latter because it does not search for a specific directory, but rather searches a database (/var/lib/locatedb), which contains all of the local file information. The Linux system automatically creates this database and updates it automatically every day, so you won't be using the locate command to find the most recently changed files. To avoid this, you can use the updatedb command to manually update the database before using locate.

Usages of the Locate command:

  $ locate/etc/sh

Search all files in the ETC directory that start with SH.

  $ locate ~/m

Searches the user's home directory for all files beginning with M.

  $ locate-i ~/m

Searches the user's home directory for all files that start with M and ignores case.

3. Whereis

The Whereis command can only be used for the search of program names, and only binary files (parameter-B), man description file (parameter-m), and source code files (parameter-s) are searched. If the argument is omitted, all information is returned.

Usages of the Whereis command:

  $ whereis grep

4. Which

The which command works by searching for the location of a system command in the path specified by the path variable and returning the first search result. That is, by using the which command, you can see whether a system command exists, and which location is executing the command.

Usages of the which command:

  $ which grep

5. Type

The type command is not really a lookup command, which is used to distinguish whether a command is brought by a shell or provided by a separate binary file outside the shell. If a command is an external command, then the-P argument displays the path to the command, equivalent to the which command.

Use instance of type command:

  $ type cd

The system prompts 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 grep

With the-p argument, it is equivalent to the which command.

Finish

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.