Detailed description of the find command in Linux:
Reproduced from Baidu Encyclopedia:
Name: Find
Usage: Find [path] [expression]
Instructions for use:
There are more than 20 or 30 options available in expression. Here, we will only introduce the most commonly used options.
-Mount,-xdev: Only checks the files in the same file system as the specified directory to avoid listing the files in other file systems.
Archives
-Amin-N: Read in the last n minutes
-Amin N: it was read n minutes ago.
-Anewer file: The file that has been read later than the file.
-Atime-N: Files Read in the last n days
-Atime N: File Read n days ago
-Cmin-N: modified in the last n minutes
-Cmin N: modified n minutes ago
-Cnewer file: The file that is updated than the file.
-Ctime-N: Files modified in the last n days
-Ctime N: File Modified n days ago
-Empty: empty file-gid N or-group name: GID is N or group name is name
-Ipath P,-path P: The file whose path name is P-compliant. ipath ignores case sensitivity.
-Name,-INAME name: name of the file that matches the name. INAME ignores case sensitivity.
-Size N [cwbkmg]: The file size is n data blocks determined by the suffix. The suffix indicates:
B: indicates the block of the 512-bit tuples. (If the suffix is not specified, the default value is B)
C: The number of bytes.
K: Kilo bytes (1024 bytes)
W: Word (2 bytes)
M: MB (1048576 bytes)
G: Gigabit (1073741824 bytes)
-Type C: the archive type is C.
D: Directory
C: font Device File
B: block device Archives
P: named storage Column
F: General Files
L: Symbolic Link
S: Socket
-Pid N: file whose process ID is n
You can use () to separate the operators and use the following operations.
Exp1-And exp2
! Expr
-Not expr
Exp1-or exp2
Exp1, exp2
Example:
List all files with C extension files under the current directory and Its subdirectories.
# Find.-Name "*. c"
List all common files in the subdirectories of the current directory
# Find.-FTYPE F
List all files updated in the last 20 days under the current directory and Its subdirectories
# Find.-ctime-20
Reprinted from:Http://www.jz123.cn/text/1720453.html? 1349293925
Each operating system is composed of thousands of different types of files. The system has its own files.
User Files, shared files, and so on. Sometimes we often forget where a file is stored on the hard disk. In
In Microsoft's Windows operating system, it is quite easy to find a file, as long as you click "start"-"Search" on the desktop
You can search for various files and documents on the local hard disk, local area network, or even on the Internet in various ways.
However, users who use Linux are not so lucky. Finding a file on Linux is really troublesome.
Situation. After all, in Linux, we need to use a dedicated "Search" command to find files on the hard disk. File expression in Linux
The format is very complex. Unlike windows, DOS uses the unified aaaaaaa. BBB format for convenient search.
In Windows, you only need to know the file name or suffix of the file to be searched. Search for files in Linux
The "find" command is usually used to manage Linux daily transactions.
Files. For new Linux users, the "find" command is also a method to understand and learn the characteristics of Linux Files. Because
Linux has a wide variety of releases and fast version upgrades. in Linux books, the location of a configuration file is often indicated.
Linux beginners still cannot find it by image. For example, RedHat Linux 7. O and RedHat Linux 7.1 are important.
The hard disk location and directory of the configuration file have changed a lot. If you do not learn to use the "find" command
It is quite difficult to find one of the thousands of Linux Files. I am not proficient in the "find" command
I have suffered this kind of hardship before. The following describes in detail how to use and use the powerful "find" command.
Each operating system is composed of thousands of different types of files. The system has its own files.
, User files, shared files, and so on. Sometimes we often forget where a file is stored on the hard disk.
. Searching for a file in Microsoft's Windows operating system is quite simple, as long as you click "start" on the desktop"
-You can search for files and documents on a local hard disk, local area network, or even on the Internet in various ways.
.
However, users who use Linux are not so lucky. Finding a file on Linux is really troublesome.
Situation. After all, in Linux, we need to use a dedicated "Search" command to find files on the hard disk. File expression in Linux
The format is very complex. Unlike windows, DOS uses the unified aaaaaaa. BBB format for convenient search.
In Windows, you only need to know the file name or suffix of the file to be searched. Search for files in Linux
The "find" command is usually used to manage Linux daily transactions.
Files. For new Linux users, the "find" command is also a method to understand and learn the characteristics of Linux Files. Because
Linux has a wide variety of releases and fast version upgrades. in Linux books, the location of a configuration file is often indicated.
Linux beginners still cannot find it by image. For example, RedHat Linux 7. O and RedHat Linux 7.1 are important.
The hard disk location and directory of the configuration file have changed a lot. If you do not learn to use the "find" command
It is quite difficult to find one of the thousands of Linux Files. I am not proficient in the "find" command
I have suffered this kind of hardship before. The following describes in detail how to use and use the powerful "find" command.
Search by File Name:
This method is as easy to understand as searching for files in windows. If you put this file in a single
Folder, as long as you use the common "ls" command to easily find out, then use the "find" command to find it
You cannot be deeply impressed. After all, the "find" command has more powerful functions than that. If you know the file name of a file
But does not know which folder the file is stored in, or even layers of embedded folders. For example, if you forget
The httpd. conf file is located in the directory of the system, or even somewhere in the system.
Command:
Find/-name httpd. conf
This command syntax seems easy to understand, that is, write-name directly after find, indicating that the system needs to follow
Find the file name, and write httpd. conf as the target file name. Wait a moment. The system will display it on the computer screen.
Search Result List:
ETC/httpd/CONF/httpd. conf
This is the complete path of the httpd. conf file in Linux. Search successful.
If the system does not display the result after you enter the preceding SEARCH Command, do not assume that the system has not executed the find/-name command.
The httpd. conf command may be because the Apache server is not installed in your system.
Server, and then use find/-name httpd. conf to find the configuration file.
No error search skills:
In Linux, the "find" command is a command that can be used by most system users, not by the root system administrator.
Patents. However, common users may encounter this problem when using the "find" command, that is, the system administrator in the Linux system.
Root can set some file directories to the Access prohibited mode. In this way, normal users do not have the permission to use the "find" command to query
These directories or files. When common users use the "find" command to query these file directories
"Permissiondenied." (Access prohibited. The system will not be able to query the files you want. To avoid such errors
, But we tried to find the file by using the transfer error prompt, enter
Find/-name access_log 2>/dev/null
This method transfers the search error prompt to a specific directory. The system encountered an error message after executing this command.
Information is directly transmitted to stderrstream 2, access_log 2 indicates that the system will send the error information
In stderrstream 2,/dev/null is a special file that indicates null or error information, so that the queried error message is
Information will be transferred and will not be displayed again.
In Linux, you may encounter such a problem when searching for files. If we find
It takes a long time for a file, especially for large Linux systems and large-capacity hard disks.
In a very deep directory. If we know that this file is stored in a large directory
To save a lot of time. Use Find/etc-name httpd. conf to solve this problem. Above life
In the etc directory, query the httpd. conf file. Here we will describe the meaning of the "/" function symbol. If
Input "find/" indicates that the Linux system is required to search for files in the entire root directory, that is, to search for files on the entire hard disk.
While "find/etc" is to find files only in the etc directory. Because "find/etc" indicates that only files are searched in the etc directory
The search speed is much faster.
Method for searching based on some file names:
This method is the same as finding known file names in windows. However, in Linux
The method of searching for files by name is much more powerful than that of similar methods in windows. For example, we know a file package
If you have three SRM letters, you can find all the files in the system that contain these three letters. Enter:
Find/etc-name '* SRM *'
This command indicates that the Linux system will find all the files containing the three letters SRM in the/etc directory.
Such as absrmyz, tibc. SRM, and other eligible files can be displayed. If you still know that this file is composed of three
You can also omit the asterisks. The command is as follows:
Find/etc-name 'srm *'
This is only available for files like srmyz. files like absrmyz or absrm do not match
Is not displayed, so the efficiency and reliability of file searching are greatly enhanced.
Query methods based on file features:
If you only know the size of a file, modify the date and other features, you can use the "find" command to find out.
In Windows, the "Search" function is basically the same. In Microsoft's "Search", the "search assistant" in Windows enables
It is easier to search for files and folders, printers, users, and other computers on the network. It even makes it on the Internet
Search is easier. The search assistant also includes an index service that maintains the indexes of all files in the computer
The search speed is faster. When you use "search assistant", you can specify multiple search criteria. For example, you can
And search for files and folders. You can even search for files containing specific text. If the user is using active
Directory, you can also search for a printer with a specific name or location.
For example, if we know that the size of a Linux File is 1,500 bytes, we can use the following command to query find /-
Size 1500c, character C indicates the size of the file to be searched is measured in bytes. If we connect
The body size is unknown, so you can perform fuzzy search in Linux. For example, enter find/-size.
+ When 000c is used, it indicates that the specified system finds a file larger than 10000000 bytes in the root directory and displays
. "+" In the command indicates that only files larger than the specified size are required to be listed, and "-" indicates that the system column is required.
Output a file smaller than the specified size. The following list is the search action that the system will perform after using different "find" commands in Linux.
In Linux, we can easily see that there are many ways to use the "find" command, and the "find" command is flexible to find files.
In Windows.
Find/-Amin-10 # search for files accessed in the last 10 minutes in the system
Find/-atime-2 # search for files accessed in the last 48 hours in the system
Find/-empty # search for files or folders that are empty in the system
Find/-group cat # Find the groupcat file in the system
Find/-mmin-5 # search for the files modified in the last 5 minutes in the system
Find/-mtime-1 # search for files modified in the last 24 hours in the system
Find/-nouser # search for files belonging to the void user in the system
Find/-user Fred # search for files belonging to the user Fred IN THE SYSTEM
The following list is some of the conditions for searching the features of files that can be specified by the find command. Not listed here
For more information about all the search conditions, see related Linux books to find the search functions of all the FIND commands.
-Amin n
Find the files accessed in the last n minutes of the system
-Atime n
Find the last n * 24 hours of files in the system
-Cmin n
Searches for the files in the last n minutes that have been changed.
-Ctime n
Searches for the last n * 24 hours of files in the system that have been changed.
-Empty
Search for Blank files, empty file directories, or folders without subdirectories in the system.
-False
Find files that are always wrong in the system
-Fstype type
Search for files in the specified file system, for example, ext2.
-Gid n
Find the file whose ID is N in the system.
-Group gname
Find the files in the system that belong to the gnam file group and specify the group and ID.
Description of the control options of the find command:
The find command also provides some special options for users to control the search operation. The following table lists the basic information we have summarized,
The control options and usage of the most common find command.
Option
Purpose description
-Daystart
. Test the system's files within 24 hours from today. usage is similar to-Amin
-Depth
Using the depth-level search process, you can first find the file content in the specified directory at a layer.
-Follow
Follow the wildcard link query method. In addition, you can ignore the wildcard link query method.
-Help
Show command Summary
-Maxdepth levels
Search for directories at a certain level by the descending Method
-Mount
It is not found in the file system directory. The usage is similar to-xdev.
-Noleaf
Do not optimize searches in non-unux file systems, MS-DOS systems, CD-ROM file systems
-Version
Print version numbers
After the-follow option is used, the find command follows the wildcard Link Method for search, unless you specify this option, otherwise
In general, the find command ignores the wildcard link for file search.
-The purpose of the maxdepth option is to restrict the find command to search for files in directories in descending mode.
Through a certain level or searching too many directories, resulting in slow query speed and excessive search time. For example, we
To find a file named Fred in the subdirectory of the current (.) Directory tip, run the following command:
Find.-maxdepth 2-name Fred
If the Fred file is in the./sub1/Fred directory, the command will directly locate the file and it is easy to find it.
Successful. If the file is in the./sub1/sub2/Fred directory, this command cannot be found. Because
The maximum Query Directory level of the find command in the directory is 2. You can only search for files under the 2-tier directory. The purpose is
Allows the find command to locate files more accurately. If you know the approximate file directory level of a file
After adding-maxdepth N, you can quickly find it in the specified directory.
Search for files using hybrid search
The find command can use the mixed search method. For example, we want to find more than 100000000 bytes in the/tmp directory and
For a File Modified within 48 hours, we can use-and to link the two search options into a hybrid
Search Method.
Find/tmp-size + 0000000c-and-mtime + 2
All the friends who have learned computer languages know that in computer languages, they use and or to indicate the relationship between "and" and "or", respectively.
. Search commands in Linux are also common.
In addition,
Find/-user Fred-or-user George
We can interpret it as finding files belonging to both Fred and George in the/tmp directory.
You can also use the "Non" link in the "find" command to find files. If you want to find all files that do not belong to the/tmp directory
Panda file, using a simple
Find/tmp! -User panda
Command to solve the problem. Very simple.
How to find and display files
It is our purpose to find a file. We want to know the details and attributes of the file. If we
It is quite tedious to use the LS command to view the file information. Now we can also use these two Commands
In combination.
Find/-name "httpd. conf"-ls
After finding the httpd. conf file, the system displays the httpd. conf file on the screen.
12063 34-RW-r -- 1 Root 33545 Dec 30/etc/httpd/CONF/httpd. conf
The following table lists common parameters and usage methods for searching and displaying file information.
Option
Purpose description
-Exec command;
Search for and execute commands
-Fprint File
Print the complete file name
-Fprint0 File
Print the complete file name, including Empty files
-Fprintf File Format
Print File Format
-OK command;
Run commands for the user and confirm the input according to user y.
-Printf format
Print File Format
-Ls
Print files of the same file format.
Conclusion: We have learned how to use the find command and listed many common
Find Command Options. If we are familiar with how to use the find command in Linux
It is not a difficult task.