What are the commands for viewing files in Linux?

王林
Release: 2024-02-19 20:09:03
forward
716 people have browsed it

What are the commands for viewing files in Linux?

In Linux systems, there are five commonly used commands for viewing files, including find, locate, whereis, which and type. Next, we will introduce the usage of these five commands in detail.

 Five commands to view 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

 : The directory to be searched and all its subdirectories. Defaults to the current directory.

 : Characteristics of the files to be searched.

 : perform specific processing on the search results.

If no parameters are added, find will search the current directory and its subdirectories by default, and will not filter any results and display them all on the screen.

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 a database that contains all local file information. The Linux system automatically creates this database and automatically 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 using 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 searches binary files, man documentation files and source code files. If parameters are omitted, all information is returned.

Examples of using the whereis command:

 $ whereis grep

4. whice

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

 Usage examples of which command:

 $ which grep

5. type

The type command is not actually a search command. It is used to distinguish whether a command comes with the shell or is provided by an independent binary file outside the shell. If a command is an external command, then using the -p parameter will display the path of the command, which is equivalent to the which command.

Examples 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

The above is the detailed content of What are the commands for viewing files in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template