Five search commands in Linux and five search commands in Linux

Source: Internet
Author: User

Five search commands in Linux and five search commands in Linux

Recently, I am studying Linux. Below are some notes.

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

In Linux, there are many ways to do this. The foreign website LinuxHaxor summarizes Five Commands. You can check several of them. Most programmers may often use two to three of them. There should be not many people familiar with these five commands.


1. find

Find is the most common and powerful search command. You can use it to find any file you want.

The format of find is as follows:

$ Find <specified directory> <specified condition> <specified action>

-<Specified directory>: the directory to be searched and all its subdirectories. The current directory is used by default.

-<Specified condition>: the features of the file to be searched.

-<Specified action>: perform specific processing on the search results.

If no parameters are 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.

Find instance:

$ Find.-name 'my *'

Search for all files whose names start with "my" in the current directory (including subdirectories, the same as below.

$ Find.-name 'my * '-ls

Search for all files whose names start with "my" in the current directory and display their details.

$ Find.-type f-mmin-10

Search for all common files in the current directory that have been updated in the past 10 minutes. If the-type f parameter is not added, search for common files + special files + directories.


2. locate

The locate command is actually another method of writing "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

Search for all files starting with sh in the etc directory.

$ Locate ~ /M

Search all files starting with m in the user's home directory.

$ Locate-I ~ /M

Search all files starting with m in the user's home directory, and ignore the case.


3. whereis

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

Examples of using the whereis command:

$ Whereis grep

4. which

The 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. type

The type command is actually not a search command. It is used to identify whether a command is provided by shell or an independent binary file outside the 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 the type COMMAND:

$ Type cd

The system will prompt that cd is the built-in shell Command (build-in ).

$ Type grep

The system prompts that grep is an external command and displays the path of the command.

$ Type-p grep

After the-p parameter is added, it is equivalent to the which command.

Reference: http://www.ruanyifeng.com/blog/2009/10/5_ways_to_search_for_files_using_the_terminal.html

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.