Linux and UNIX

xiaoxiao2021-03-06  67

F I n d Command general form is: Find pathname -Options [-print -exec -ok] Let's take a look at the parameter of the command: the Pathname Find command finds the directory path. For example, use. To represent the current directory, use / to represent the system root directory. The -print find command outputs the matching file to a standard output. The -EXEC Find command performs the S H E L command given by the matching file. Form of these commands is 'c o m m -and' {} / ;, and attention {} /; the space between. (The exec option follows the command to be executed, then a pair of children {}, a space and one /, the last is a semicolon.) - OK and - Exec are the same, but in a more secure The mode to perform the shell command given by this parameter. You will give a prompt before performing each command, allowing the user to determine if it is executed. f i n d has a lot of options or expressions, each with a horizontal bar in front of each option. Let's first take a look at the main options for this command, then give some examples. -name finds a file according to the file name. -Perm Find files in accordance with file permissions. -Prune Use this option to make F i n d in the currently specified directory, if you use the-D e P T H option, then the P R U n E option is ignored by the f i n d command. -user Find files according to the owner of the file. -group Find files in accordance with the group belonging to the file. -mtime -n n Find files according to the change time of the file, - n indicates that the file change time is now N days, n indicates that the file change time is now N days. F i n d or - a t i m e and - c t i m e option, but they are similar to-M t i m e option, so we only introduce the M T I m E option here. -NOGROUP looks out that the file where the college group is not, that is, the group to which the file belongs is not present in / e t C / G R O u P s. -nouser finds a file without a valid home, that is, the owner of the file does not exist in / e t C / P A S W. -newer file1! file2 lookup change time is new than file F i l E 1 new file File f i l e 2 old file. -type finds a type of file, such as: B - block device file. D - directory. C - Character device file. P - pipe file. l - symbolic link file. f - normal file. -size n [c] Find files with file length N block, with C indicates that the file length is byte. -Depth When looking up a file, look for files in the current directory before looking for files in its subdirectory. -fstype Find files in a certain type of file system that can usually be found in configuration file / e t c / f s t a b, which contains information about file systems in this system. -mount does not cross the file system M O U n T point when looking for files. -follow If the F I n D command encounters a symbolic link file, track the file pointed to the link. -CPIO uses the C P i O command to match the match to the tape device.

Several tips If you want to use this option to use the file command to find files within two hours unless there is a ready-made file that changes its change time just before two hours, it will not be used to compare the time. file. To solve this problem, you can first create a file and set the date and timestamp to the time required. This can be implemented with the T O U c h command. Suppose the current time is 2 3: 4 0, I hope to find the file within two hours, you can first create such a file: Touch -t 05042140 DSTAMP a qualified file has been created; here we assume that today is five On the four days, the change time of the document is 2 1: 4 0, but it is just two hours earlier. Now we can use the Find command - the newer option to find all changes within two hours of the current directory: find. -Newer dstamp -print In order to find changes in the 5th in the / logs directory and Delete them, you can use: find logs -type f -mtime 5 -exec rm {} /;

When Xargs handles the matching files using the f i n d - e x e c option, the f i n d commands all matched files to e x e c. Unfortunately, some systems have restrictions on the length of the command that can be passed to the E x E C, so that the overflow error will occur after the F i n d command is running. Error information is usually "parameter column too long" or "parameter column overflow". This is where the X A RG S command is located, especially with the F I n d command. F i n d command passes the matching file to the x a rg s command, and the X A RG S command receives only a part of the files per time, not all, not like-e x e c option. This will deal with the first part of the file, then the next batch, and continue.

Use the xargs with the find command, such as: Find all users with read, write, and execute permissions in / apps / audit directory, and recover corresponding write permissions: Find / Apps / Audit -Perm -7 -Print | xargs chmod OW In the example below, we use the grep command to search for Device in all normal files: Find / -Type F -PRINT | Xargs Grep "Device"

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

New Post(0)