Home > Article > Operation and Maintenance > What are the commands for viewing files in Linux?
There are five commands for viewing files in Linux, namely: 1. find command, which can find any desired file; 2. locate command, which cannot find the latest changed files; 3. whereis command, Only binary files, man files and source code files are searched; 4. which command, which checks whether a certain system command exists and which position the command is executed; 5. type command, which distinguishes whether a certain command is executed by the shell itself. It is provided by an independent binary file outside the shell.
When using a computer, you often need to find files. In Linux, there are many ways to do this. Here are five commands summarized for you.
Five commands for viewing files in Linux:
find is the most common and powerful search command. You can use It finds any file you're looking for.
$ find <指定目录> <指定条件> <指定动作>
- <指定目录>: 所要搜索的目录及其所有子目录。默认为当前目录。 - <指定条件>: 所要搜索的文件的特征。 - <指定动作>: 对搜索结果进行特定的处理。
If no parameters are added, find will search the current directory and its subdirectories by default, and will not filter any results (that is, return all files). They are all displayed on the screen.
Search for all files in the current directory (including subdirectories, the same below) whose file names begin with my.
$ find . -name 'my*'
Search for all files in the current directory whose file names begin with my and display their detailed information.
$ find . -name 'my*' -ls
Search in the current directory for all ordinary files that have been updated in the past 10 minutes. If the -type f parameter is not added, ordinary files and special files directories are searched.
$ find . -type f -mmin -10
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 Search a database (/var/lib/locatedb
), which contains all local file information. The Linux system automatically creates this database and updates it automatically 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.
Search for all files starting with sh in the etc directory.
$ locate /etc/sh
Search for all files starting with m in the user's home directory.
$ locate ~/m
Search for all files starting with m in the user's home directory, and ignore case.
$ locate -i ~/m
thewhereis command can only be used to search for program names, and only searches binary files (parameter -b), man description files (parameter -m) and source code files (parameter -s). If parameters are omitted, all information is returned. Examples of using the
$ whereis grep
which command is used 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. Examples of using the
$ which grep
type command is not actually a search command. It is used to distinguish whether a certain command is provided by the shell. , or provided by a separate 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.
The system will prompt that cd is the shell’s built-in command (build-in).
$ 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 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!