Linux common search command

  
1. find find is the most common and powerful search command, you can use it to find any file you are looking for. The find command makes it easy to find the specified file you need in your Windows system. The format of find is as follows: $ find <specified directory> <specified condition> <specified action> - <specified directory>: directory to be searched and all its subdirectories. The default is the current directory. Can be a directory listing separated by spaces. - <specified condition>: The characteristics of the file to be searched. Expression Description -name file Tells find what file to look for; the file to be found is enclosed in quotation marks. You can use wildcards (* and ?) -perm mode to match all files whose mode is the specified numeric mode value. Not just reading, writing and executing, all patterns must match. If the pattern is preceded by a minus sign (-), it means that all modes except this mode are used. -type x matches all files of type x. x is c (character special), b (block special), d (directory), p (named pipe), l (symbolic link), s (socket file) or f (general file). -links n matches all files with n connections. -user user number Matches all files whose user serial number is the user serial number specified earlier, which can be a numeric value or a user login name. -atime n Matches all files that have been accessed in the previous n days. -mtime n matches all files that have been modified in the previous n days. The -newer file matches all files whose modification time is newer than the file file. -size n Matches all files of size n blocks (512-byte blocks, if k is after n, it is a 1K-byte block). -print Displays the entire file path and name. In general, use -print, if there is no such parameter, the find command does not display the result of the required search. - <Specify action>: Perform specific processing on the search result. If nothing is added, find defaults to the current directory and its subdirectories, and does not filter any results (that is, returns all files), displaying them all on the screen. The use of find: $ find . -name 'my*' Search for the current directory (including subdirectories, the same below), all files whose names begin with my. $ find . -name 'my*' -ls Searches for files in the current directory with all file names starting with my and displays their details. $ find . -type f -mmin -10 Searches all the normal files that have been updated in the past 10 minutes in the current directory. If the -type f parameter is not added, the normal file + special file + directory is searched. 1) I know the file name of a file, but I don't know which directory it is stored in. At this point, I can find the file by looking up the command. The command is as follows: # find /-name httpd.conf –print 2) According to some files Name Search When you want to find a file, you don't know the full name of the file. You only know that the file contains several specific letters. You can also find the corresponding file by using the find command. At this time, the wildcard ""*”,“? ”. For example, still look for the file “httpd.conf”, but just remember that the file name contains the “http” string, which can be found using the following command: #find /–name *http* -print 3) Find according to the characteristics of the file If you only know the size of a file, the date of modification, and other features, you can use the find command to find the file. For example, to know that a file size is less than 2500 bytes, you can use the following command to find: #find /etc –size -2500c –print The following is the parameter of the find command function with the time feature as the search condition: amin n find n minutes ago All files accessed. Atime n Finds all files that have been accessed n days ago. Cmin n Finds all files whose file status has been modified n minutes ago. Ctime n Finds all files whose file status has been modified n days ago. Mmin n Finds all files whose file contents have been modified n minutes ago. Mtime n Finds all files whose file contents have been modified n days ago. 2. The locate locate command is actually another way of writing "find -name", but it is much faster than the latter because it does not search for a specific directory, but instead searches for a database (/var/lib/locatedb). This database contains all local file information. The Linux system automatically creates this database and automatically updates it once a day, so you can't find the latest changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate. Example of the use of the locate command: $ locate /etc/sh Search for all files starting with sh in the etc directory. $ locate ~/m Searches all files starting with m in the user's home directory. $ locate -i ~/m Searches all files starting with m in the user's home directory and ignores case. 3. The whereis whereis command can only be used for program name search, and only search binary files (parameter -b), man description file (parameter -m) and source code file (parameter -s). If the parameter is omitted, all information is returned. Example of the whereis command: $ whereis grep 4. The function of which which 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. In other words, using the which command, you can see if a system command exists and which command is executed. Example of which command: $ which grep 5. The type type command can't be used as a lookup command. It is used to distinguish whether a command is provided by the shell or by an independent binary file outside the shell. If a command is an external command, then using the -p parameter will display the path to the command, which is equivalent to the which command. Example of the use of the type command: $ type cd The system will prompt, cd is the shell's own command (build-in). $type grep The system prompts that grep is an external command and shows the path to the command. $ type -p grep With the -p parameter, it is equivalent to the which command.
Copyright © Windows knowledge All Rights Reserved