Wen Qi Find Technology Daquan in Linux

xiaoxiao2021-03-06  14

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 what you can use: find / -name httpd.conf This command syntax looks It's easy to understand, just write up to -name directly after Find, indicating that the system is found in the file name, and finally write httpd.conf this target file name. Take a little later system will display the list of find results on the computer screen: etc / httpd / conf / httpd.conf This is the full path to the 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 containing these three letters in the system, enter: find / etc -name '* srm *' This command indicates Linux. The system will look for all files containing SRM's 3 letters, such as Absrmyz, Tibc.srm, etc., 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 forefront of the asterisk, the command is as follows: Find / etc -name 'SRM *' This is only a file like SRMYZ is only found. Out, like Absrmyz or ABSRM does not meet the requirements, not displayed, so 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 # found in the system Find / -user Fred # below the list below the Fred file below the list below is some of the conditions for finding the feature 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 The system file, for example: ext2. -Gid n Find the file in the file in the system, file -Group GName finds the file in the GNAM file group, and the file Find command for the specified group and ID Find command: 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. Options Use the -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; , You can also ignore the wildcard link method query -help display command Summary -MaxDepth Levels In a level directory, follow the Decremen method to find in the file system directory, usage similar to -XDEV. -Noleaf is prohibited 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 The command will directly locate this file and look up is easy to succeed. 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 students learning computer language know that in computer languages, use and "and" or "relationships. 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 two users belonging to FRED or George 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. The Find / -Name "httpd.conf" -ls 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 field finding files and display the parameters of file information and how to use options Description -Exec Command; Find and execute a command -fprint file Print file full file name -fprint0 file print file full file name includes empty file -fprintf file format print file format -ok command; give the user command, according to the user's Y Confirm input execution -Printf Format print file format -LS print files in the same file format. Find introduction -

Find is actually a very useful tool, and common tools.

◎ Find - Walk A File Hierarchy

Tourism in a archive level system is also searching

◎ Syntax:

Find path Operators

PATH: Path Operators: Operator (parameter)

◎ Operators: Commonly used parameters are as follows (if there is doubt, please refer to Man Page)

★ indicates important ...

1.

-Atime N: Use file access time (Access) as search criteria, n is the number representative cycle,

The unit is 24 hours.

★ Note: N does not bring a positive and negative, indicating that the current cycle is from the next cycle.

n When the negative is negative (-), it means that the period is previously.

n is a positive number ( ) indicating that the time greater than this cycle is greater than this cycle.

for example:

If n is 3 (without the positive or negative), it is shown in 62 to 96 hours. If N is -3 (with negative), it means that the distance is within 0 ~ 72 hours.

If N is 3 (with a positive number), it means that it is more than 72 hours, that is,> 72 hours.

2.

-mtime N: Use the file modification time (Modification) to search criteria, n in a 24-hour period.

3.

-ctime N: Dividing the file inode inode, n is cycle 24 hours.

4.

-inum n: Use the inode value as the search criterion, n is the inode value of the file.

5.

-Name FileName: The name of the post file, if you include "Wan Dynasty", you have to enclose.

Avoid SHELL interpretation.

6.

-Perm Mode: Search for access rights.

7.

-user name: With the owner of the file, you can use the UID.

8.

-group name: The group is searching for the group, and GID can also be used.

Note: 7.8 Find will use Name to search, if you can't find it, try to search with UID or GID

9.

-type T: T represents the type of file, the type is commonly used:

D -> Data Clip

F -> General file

l -> symbol connection

10.

-Size N: n represents the number of blocks, usually 512-byte bolck,

If N, then C (NC) is represented as n bytes.

★ 11.

Operator1 -a operator2: -a equivalent to logical and

Operator1 -o operator2: -o is equivalent to logical OR

! Operator1:! Is equivalent to logical Not

Note:

Operator1 -a operator2

Operator1 Operator2

It is the same ... The same representative of the operational operator 1 is established and the operator 2 is established.

★ 12.

/ (Expression /): In the complex case, parentheses indicate first operation.

Plus the anti-slope / is not to let the shell mistaken.

13.

-print: Sending the results to the standard output stdout, which is generally the screen.

Note: Parameters that are most common but often forgotten.

★ 14.

-EXEC Command: Indicates the result of the search and imports an order.

Note: The results of the search can be replaced by two braces {}, and the command is followed /; indicates the end.

EX: Search the current directory to delete the files ended! !

Find. -Name "* .o" -exec rm -f {} /;

★ 15.

-maxdepth n: n represents the depth of the search. 1 Represents the current folder.

★ 16.

-ok command: -ok is the same as -EXEC, but it will be inquired before execution. Usually used to test.

★ 17.

-newer file: The time earlier than File modification is earlier for search criteria

◎ Example application:

1. Modifying time: Suppose is the file in this directory 7 days ago (Day)

Find. -mtime 7 -print

Find. -mtime 6 -MTIME -8 -PRINT

2. Archive size: All files are between 1000byte to 32000byte

Find. -size 1000c -size -32000c -print

★ 3. Delete some strange files: Some files cannot be deleted due to special flocks,

Find. -INUM 31246 -EXEC RM-RF {} /

Note: 31246 is a value of INODE, available

LS -I looks..

★ 4. Search with exact time: Search for all files a in May 28, 2001 to 0:10 May 29, 2001.

Touch -t 200105281159 file1

b.

Touch -t 200105290010 file2

C.

Find. -newer file1! -newer file2 -print

This will search for several files to deduct FILE2 ...

★ 5. Change the file: rename the search

Find. -maxdepth 1 -Name "* .o" -exec mv {} {} .orig

Additional file names that match the file in accordance with the file .orig

★ Note: If your fifth cannot be executed, you can do this:

$

Find. -maxdepth 1 -Name "* .o" |> while read file> do mv "$ file" "$ file" .orig> DONE

> It is the prompt symbol that automatically appears after the wrap ...

★ 6. Find the file in the file: (this example is Success)

Find. -type f -exec "success" {} / dev / null /;

★ Note: Nothing plus / dev / null will generate unable to learn the results of the search matching file name.

If you add / dev / null, Grep will make the two files each time, and the search results are generated.

Of course .. If you usually write, you can write Script, such as Find2.

IF Test $ 1 The Find. -type f -exec Grep $ 1 / dev / null {} /; else echo "The correct syntax is: ./find2 search word" FI

◎ Important concept:

★ 1. Search parameters are all conventional representations of find, if the representation is true, there are some set actions.

★ 2. The first operation in parentheses:

-time 5 / (-name "* .o" -o -name "* .tmp" /)

Indicates that the search access time is greater than 5 days and (name * .o or * .tmp)

3. If there are two operations in the rule-style, if you are separated by a blank, -A is also an

★ 4.Find task is to determine the entire arithmetic, rather than finding a file,

Of course, you will find a file, but that is just a side effect.

5. Try not to search for NFS files, because if NFS Server hangs, let the entire search pause.

Can be restricted with -maxdepth or -prune

◎ Difficult to eliminate:

★ xargs use:

Sometimes you encounter this situation ... The syntax is correct but it can't display

Find / -print | ls -al displays all files in the root directory

The system will directly appear Broken Pine and then end ...

Or there is a TOO MANY Argument .. then indicates the length of the output exceeds the instruction column.

It is necessary to use Xargs at this time ... The whole command is as follows

Find / -Print | xargs ls -al

The result will appear smoothly .. Because Xargs will enter a one-sequential output,

Not all.

Description: Xargs seems useless, but it is intentionally unverified.

- Author: netsec January 8, 2005, Saturday, 18:45

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

New Post(0)