1. find
Find is the most common and powerful search command. You can use it to find any file you want. The find command allows you to conveniently find the required specified file in the use and management of Linux systems.
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. A directory list separated by spaces.
-<Specified condition>: the features of the file to be searched.
Expression
Description
-Name File
Tell find what file to find. The file to be searched is included in quotation marks. wildcards (* And?) can be used ?)
-Perm Mode
Matches all files whose modes are specified numeric values. Not only read, write, and execute, all modes must match. If it is a minus sign (-) before the mode, all modes except this mode are used.
-Type x
Match all objects of the x type. X is c (special characters), B (special blocks), d (directory), p (famous pipelines), l (symbolic connections), s (nested files) or f (general file ).
-Links n
Match All files with n connections.
-User ID
The file that matches all user serial numbers is the user serial number specified earlier. It can be a numeric value or user login name.
-Atime n
Match All files accessed in the previous n days.
-Mtime n
Match All files modified in the previous n days.
-Newer File
Match All Files updated at a time later than the file.
-Size n
Match all the files whose size is n (512 bytes. If k is n, it is 1 k bytes ).
-Print
The path and name of the entire file are displayed. In general, you must use-print. If this parameter is not used, the "find" command does not display the required search results.
-<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.
1) If you know the name of a file, but do not know the directory in which it is stored, you can find the file by using the search command. The command is as follows:
# Find/-name httpd. conf-print
2) search by some file names
When you want to find a file, you only know that the file contains several specific letters. You can use the search command to find the file. The wildcard "*" and "?" are used to search for the file name. For example, if you still want to find the file "httpd. conf", but remember that the file name contains an "http" string, you can run the following command to find it:
# Find/-name * http *-print
3) search by file features
If you only know the size and modification date of a file, you can use the find command to find the file. For example, if you know that the size of a file is smaller than 2500 bytes, you can run the following command to find it:
# Find/etc-size-2500c-print
The parameters of the find command function are as follows:
Ø amin n searches for all files accessed n minutes ago.
Atime n: search for all files that have been accessed n days ago.
Ø cmin n: searches for all files whose status has been modified n minutes ago.
Ø ctime n: searches for all files whose status has been modified n days ago.
Ø mmin n searches for all files whose contents have been modified n minutes ago.
Mtime n: searches for all files whose contents have been modified n days ago.
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.