Find by file name:
This method is as easy to understand as the finding file under Windows. If you put this file in a single folder, you can easily find it with a common "ls" command, then use the "Find" command to find it can't give you a deep impression, after all, "Find "The powerful function of the command is more than this. If you know the file name of a file, you don't know which folder is put in this file, or even the folder of the layer cover. For example, suppose you forgetting httpd.conf this file in which directory of the system, even in a certain place of the system, this is the following command:
Find / -Name httpd.conf
This command syntax looks easy, it is written directly on Find, indicating that the system is looking for by file name, and finally write httpd.conf this target file name. Take a little waiting for a list of findings on the computer screen:
ETC / httpd / conf / httpd.conf
This is the full path in this file in the Linux system. Find success.
If the system does not display the result after entering the command, then don't use the system »No Find / -Name httpd.conf command, but may be no Apache server in your system, then you have installed the Apache web server. Then you can find this configuration file again using FIND / -NAME HTTPD.CONF.
There is no error in finding skills:
The "Find" command in the Linux system is the command that most system users can use, not the patent of the root system administrator. But the ordinary users can also encounter such problems when using the "Find" command, that is, the system administrator root in the Linux system can set some file directories to disable access mode. Such a normal user has no permission to query these directories or files with the "Find" command. When the ordinary user uses the "Find" command to query these file directories, "PermissionDenied." (Forbidden access) is often appeared. The system will not be able to query the file you want. In order to avoid such errors, we use the method of transferring error prompts to find a file, enter
Find / -Name Access_log 2> / dev / null
This method is to transfer the find error prompt to a specific directory. After the system executes this command, the information encountered directly into StderrsTream 2, and Access_log 2 is indicating that the system will transport the error message to ° Stderrstream 2, / dev / null is a special file, indicating empty or wrong Information, so that the error message thus queried will be transferred and will not be displayed again.
The LINUX system finding file will also encounter such an actual problem. If we are in the entire hard drive, it takes a long time to find a file, especially the large Linux system and larger hard drive, and the file is in a deep directory. If we know that this file is stored in a big directory, you can save a lot of time as long as you find it under this directory. This issue can be solved using Find / etc -name httpd.conf. The above command is to query httpd.conf file in the ETC directory. Here, you will explain the meaning of "/" this function symbol. If you enter "FIND /" means that the LINUX system is required to find a file in the entire root directory, it is also looking for files throughout the hard disk, and "Find / ETC" is only Find files in the ETC directory. Because "find / etc" means looking for files only in the ETC directory, the speed of finding is much faster.
Find methods based on section file name:
This method is the same as finding known file names in Windows. However, the method of finding a file in Linux is much more powerful than the similar lookup method in Windows in WINDOWS. For example, we know that a file contains three letters of SRM, then find all files that contain these three letters in the system, enter: find / etc -name '* srm *'
This command indicates that the Linux system will find all files containing SRM throughout the entire directory, such as Absrmyz, Tibc.SRM, etc. Can be displayed. If you know that this file is headed by SRM, then we can also omit the most in front of the asterisk, the command is as follows:
Find / etc -name 'srm *'
This is only a file like SRMYZ, it is not compliant with files like Absrmyz or ABSRM, which is not displayed so that the efficiency and reliability of the file is greatly enhanced.
According to the feature query method:
If you only know the size of a file, you can use the "FIND" command to find out, this and the "Search" function in the Windows system is basically the same. "Search Assistant" in Windows in Microsoft's Search, makes searching files and folders, printers, users, and other computers in the network easier. It even makes it easier to search on the Internet. "Search Assistant" also includes an index service that maintains an index of all files in your computer so that the search speed is faster. When using the Search Assistant, the user can specify multiple search criteria. For example, users can search for files and folders by name, type, and size. Users can even search for files containing specific text. If the user is using Active Directory, you can also search for printers with specific names or locations.
For example, we know that a Linux file size is 1,500 bytes, then we use the following command to query Find / -Size 1500c, character c indicates that the size of the file to be found is bytes as Bytes. If we don't even know the specific size of this file, you can solve the fuzzy lookup mode in Linux. For example, we entered the Find / -Size 10000000c this command, indicate that we specify the system to find a file greater than 10,000 bytes in the root directory and display it. " " In the command is that the required system only lists the files greater than the specified size, and the "-" means that the system is required to list the files smaller than the specified size. The following list is that the search action to be made after Linux uses the "Find" command, from which we can easily see how many ways to use the "Find" command in Linux, "Find" command lookup file as long as flexible application, It is not necessary to find poor ability in Windows.
Find / -AMIN -10 # Find files accessed in the last 10 minutes of the system
Find / -Atime -2 # Find files accessed in the system last 48 hours
Find / -empty # Find files or folders in the system
Find / -Group cat # Find files that belong to GroupCAT in the system
Find / -MMIN -5 # Find files modified in the last 5 minutes in the system
Find / -MTIME -1 # Find files modified in the last 24 hours in the system
Find / -nouser # Find files that belong to invalid users in the system
Find / -user fred # Find files with Fred this user belonging to this system
The following list is some of the conditions for finding the features of the file you can specify by the FIND command. Here is not to list all lookup conditions, refer to Linux related books
Know all the find functions of all Find commands.
-amin n
Find files in the last N minute access to the system -Atime N
Find files for last N * 24 hours access in the system
-cmin n
Find files that have been changed in the system in the system
-ctime n
Find files in the last N * 24 hours of the system
-empty
Find blank files in the system, or blank file directory, or a folder without subdirectory in the directory
-false
Find a file in the system
-fstype type
The file exists in the specified file system in the search system, for example: ext2.
-gid N
Find files in files in the system Number group ID N
-group gname
Find files in the system belong to the GNAM file group and the file specified in group and ID
Control options for the Find command:
The Find command also provides some unique options to users to control the lookup operation. The following table is the most basic, most commonly used Find command we summarized and its usage.
Option
Use description
-daystart
The test system starts 24 hours today, usage Similar to -Amin
-Depth
Use the depth level lookup process, you can prioritize file content in a specified directory in a certain layer.
-FOLLOW
Follow the wildcard link mode; in addition, you can ignore the wildcard link method query
-help
Display command summary
-maxdepth level
Find in the directory of a certain level
-mount
Not looking for in the file system directory, usage is similar - xdev.
-Noleaf
It is forbidden to optimize in non-unux file systems, MS-DOS systems, and CD-ROM file systems.
-Version
Print version number
After using the -follow option, the Find command follows the wildcard link mode, unless you specify this option, otherwise the Find command will ignore the wildcard link method for file search.
-maxDepth option is to limit the find command to search the file in the directory to find a file more than a level or search for too many directories, which causes the lookup speed to slow, and the lookup takes too much time. For example, we have to find a file called Fred in the current (.) Directory Skills subdirectory, we can use the following command
Find. -maxdepth 2 -Name Fred
If this Fred file is in the ./sub1/fred directory, then this command will directly locate this file and look for it is easy. If this file is in the ./sub1/sub2/fred directory, then this command cannot be found. Because the front has already given the Find command to the largest query directory level 2, only the files in the Layer 2 directory can be found. The purpose of this is to make the find command more accurate positioning file. If you already know the file directory level number of a file, then add -maxDepth n to find success in the specified directory.
Find files using mixed lookup
The Find command can use a mixed lookup method, for example, we want to find a file greater than 10,0000000 bytes and modify within 48 hours in / tmp, we can use -and to link two lookup options to a mix Find way.
Find / tmp --size 10000000c -and -mtime 2
Friends who have learned the computer language know that in the computer language, use and "and" or "relationships, respectively. Universal as in the LINUX system lookup command.
There is still such an example.
Find / -user fred -or -user george
We can interpret files that look for Fred or George two users in the / TMP directory.
You can also use the "non-" relationship to find files in the Find command. If we want to find all files that don't belong to Panda in the / TMP directory, use a simple
Find / tmp! -user panda
The command can be solved. Very simple.
Find and display the file method
Finding a file is our purpose, we want to know the details and properties of the files that are found, if we take the search file, use the ls command to see file information is quite cumbersome, now we can also put this The two commands are combined.
Find / -Name "httpd.conf" -ls
The system displays httpd.conf file information on the screen immediately after finding the httpd.conf file.
12063 34 -RW-R - R - 1 root root 33545 DEC 30 15:36 /etc/httpd/conf/httpd.conf
The following table is some commonly used find files and display the parameters and usage methods of file information.
Option
Use description
-EXEC Command;
Find and execute commands
-fprint file
Print file full file name
-fprint0 file
Print file full file name includes empty files
-fprintf File Format
Print file format
-ok command;
Perform actions to the user command, perform the input according to the user's Y confirmation
-Printf Format
Print file format
-LS
Print files in the same file format.