Wen Qi Find Technology Daquan in Linux

xiaoxiao2021-03-05  29

File Finding Technology in Linux Transfer from: ChinaUnix

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, you want to find a file is quite simple. Just click on "Start" on the desktop - "Search" can be found on the local hard drive in a variety of ways, and even look for on 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.

Finding by file name: This method is as easy to understand as finding the 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, assuming that you have forgotten this file in the system in which the system is in the system, even if you don't know some place in 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 moment, the system will display the 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-law: "Find" command in the Linux system is the command that most system users can use, is 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 try to find files, entering the 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 names: 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's 3 letters, then we can also omit the forefront of the asterisk, order 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 of the file: If you only know the size of a file, you can use the "Find" command using the "Find" command, which is basically the same as the "Search" function in the Windows system. "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 for the last 10 minutes of the system Find / -AMPTY # Find files for the last 48 hours of the system Find / -empty # Find files or folders for empty in the system Find / -Group Cat # Find files Find / -Mmin -5 # in the system Find / -MMIN -5 # Find files FIND / -MTIME -1 # find out in the last 5 minutes of the system to modify the last 24 hours File Find / -Nouser # Find files Find / -user fred # in the system Find / -user Fred # Find files that belong to Fred this user

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 file, for example: EXT2.-GID N lookup system in file -Group gname finding files in file -Group gname finding files in the GNAM file group, and specify files for groups and ids

Control options for the Find command Description: The Find command also provides some unique options for 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.

Use the mixed lookup method to find the file Find command to use a mixed lookup method, for example, we want to find some files greater than 10,0000000 bytes and modify within 48 hours in / tmp, we can use -and to put two lookup options Links into a mixed look. 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 also 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 command to solve. Very simple.

Finding and displaying the files Finding a file is our purpose, we prefer to know the details and properties of the files that are found, if we take the search file, use the ls command to view file information is quite cumbersome, Now we can also combine these two commands. 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 fields and displays the parameters of the file information and the use of the use of the method. FPRINTF File Format prints file format -ok command; performs action to the user command, execute the file in the same file format according to the user's Y confirmation input. Summary: Summary: He has already learned this Methods to use the use of the Find command lists the options for many commonly used Find commands. If we can master the use of the Find command in Linux, then finding the file in Linux is not a difficult thing.

转载请注明原文地址:https://www.9cbs.com/read-33497.html

New Post(0)