Detailed Explanation of Commands and Functions for Viewing Files in Linux System

  In the Linux system, there are five commonly used commands for viewing files, namely: find command, locate command, whereis command, which command and type command. Next, this article will introduce these five commands in detail for you.

  Five commands for viewing files in Linux

  1、find

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

  The usage format of find is as follows:

  $ find<specified directory><specified condition><specified action>

  <specified directory>: the directory to be searched and all its subdirectories. Defaults to the current directory.

  <specified condition>: the characteristics of the file to be searched.

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

  If no parameters are added, find searches the current directory and its subdirectories by default, and displays all of them on the screen without filtering any results.

  2、locate

  The locate command is actually another way of writing "find-name", but it is much faster than the latter, because it does not search a specific directory, but searches a database that contains all local file information. The Linux system automatically creates this database and updates it once a day, so the latest changed files cannot be found using the locate command. To avoid this situation, you can use the updatedb command to manually update the database before using locate.

  Examples of use of the locate command:

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

  $ locate /etc/sh

  3、whereis

  The whereis command can only be used to search for program names, and only search for binary files, man description files, and source code files. If the parameter is omitted, all information is returned.

  Example of using the whereis command:

  $ whereis grep

  4、whice

  The function of the which command is to search for the location of a system command in the path specified by the PATH variable and return the first search result. That is to say, by using the which command, you can see whether a certain system command exists and where the command is executed.

  Example of using which command:

  $ which grep

  5、type

  The type command is not actually a search command. It is used to distinguish whether a command is provided by the shell itself or by 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 using the type command:

  The system will prompt that cd is a built-in command of the shell.

  $ type cd

  The system will prompt that grep is an external command and display the path of the command.

  $ type grep

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

Guess you like

Origin blog.csdn.net/oldboyedu1/article/details/131377836