If you use Linux, you can first consider using the Locate method, which is generally enough, and the speed is very fast, of course, you want to generate a file database [Execute Updatedb in console] before using this command, here is about the use of Find, Generality, can also be used under UNIX
Each operating system is composed of thousands of different types of files. Among them, there is a file that own itself, the user's own documents, there are shared files, etc. We sometimes I often forget which place in the hard disk is placed on a copy. In Microsoft's Windows operating system, find a file is quite simple, just click "Start" on the desktop - "Search" can be found on the local hard drive in various ways, and even in the Internet Various documents, documentation.
However, users who use Linux are not so lucky. Finding a file on Linux is really a more troublesome thing. After all, in Linux, we need to use the dedicated "Find" command to find files on the hard disk. The file expression format under Linux is very complicated. It is not like Windows, DOS is a unified AAAAAA.bbb format. In Windows, just know the file name or suffix of the file to be found, it is very easy to find. The command to find files in Linux is usually "find" command, "Find" command can help us use, manage Linux's daily transactions to find the files we need. For Linux novices, the "Find" command is also a method for understanding and learning Linux file features. Because the Linux release has a lot of release, the version is upgraded soon, often written in Linux books, where the location of a configuration file is often written, and the newcomer is still can't find it. For example, the hard disk location and file directory where some important configuration files in Redhat Linux 7.1 have changed. If you don't learn to use the "Find" command, then tens of thousands of Linux files A configuration file to find in it is quite difficult, and the author has eaten such a bitter before the "Find" command. Ok, let's introduce all the usage methods and uses of the powerful "Find" command in detail.
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 Find / -Name httpd.conf command that the system is not executed, but may be no Apache server in your system. At this time, as long as you have an 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. To avoid such errors, we use the method of transferring error prompts to try to find files, 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, it is directly delivered to STDERRSTREAM 2 directly. Access_log 2 is indicating that the system will transfer 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 containing 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 the lookup conditions, refer to Linux about books You can know the lookup functions of all Find commands.
-Amin n Finding files in the last N minute accessed file -AME N lookup system Last N * 24 hours access file -cmin n Finding the last N minutes of the final N minute, the file is changed, the final N * 24 is last N * 24 Hourly changed state file -Empty lookup system blank file, or blank file directory, or a folder without subdirectory in the directory -False lookup system is always wrong in the FSTYPE TYPE search system exists in the specified file System files, such as: ext2.-GID N lookup system file-in file -Group GName finding files belong to the GNAM file group, and the control options for file Find commands for the specified group and ID: find command Also provide 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 Purpose Description - DayStart. Test system starts 24 hours today, usage Similar to -Amin-Depth uses depth level lookup process mode, prioritize file content in a specified directory - Follow Follow the wildcard link method; Also ignore the wildcard link method Query -help display command summary -MaxDepth level in a level directory Find -Mount Not in the file system directory, usage similar to -XDev.-Noleaf Prohibition in a non-Unux file system, MS-DOS system, Optimized in the CD-ROM file system to find -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 if you specify this option. The wildcard link is used 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.
Summary: From here, we have learned the method of using the more about the Find command, listing the options for many commonly used Find commands, if we can master the use of the Find command in Linux, then find in Linux Documents are not a difficult thing.