File name Lookup command find

Source: Internet
Author: User

One, file Lookup command

There are quite good search commands under Linux. How do you find a file's storage path? Usually we will use the following three commands:

which view the location of the executable file.

whereis View the location of the file.

Locate to view the file location with the database.

Find actual search hard disk query file name.

Usually we use the first three commands to find out, if we really can't find it. Then use the Find command to locate the. Because Whereis and Locata use the database to find the data, and they don't actually find the hard disk, so it's pretty fast.

Two, the Find command

Find is a very powerful command that is directly looking for the hard disk. The Linux Find command provides quite a lot of search criteria and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at. Even if the system contains a network file system (NFS), the Find command works equally well in the file system, and you only have the appropriate permissions. When running a very resource-intensive find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system with more than 30G bytes).

1, command format:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/4D/wKioL1c9hieSH39eAAAQ61zQY58647.png "title=" 2.PNG " alt= "Wkiol1c9hiesh39eaaaq61zqy58647.png"/>

2, Command function:

Used to locate files in the file tree and make appropriate processing (possibly accessing the disk)

3, command parameters:

Path to the directory found by the path find command. For example, use. To represent the current directory, and/to represent the system root directory.

option to select the command parameter.

The action contains these several options:

The-print find command outputs the matched file to standard output. The-exec find command executes the shell command given by this parameter to the matching file. The corresponding command is in the form of ' command ' {} \;, note the space between {} and \;

The-ok and-exec function the same, except that the shell command given by the parameter is executed in a more secure mode, and a prompt is given before each command to let the user determine whether to execute.

4, Command options:

(1) Time-related parameters:-atime-ctime-mtime The following is illustrated with-mtime as an example:

-mtime n : N is a number that has been changed in "one day or less" before the meaning of n days;

-mtime +n : Lists the file names that were changed before n days (excluding the N-day itself);

-mtime-n : Lists filenames that have been changed within n days (including n days themselves);

-newer Files: File is a file that exists, listing the name of a new filename that is newer than files.

-newer file1! file2 Find changed time than file File1 new but older file than file file2.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/51/wKiom1c9q73RHorhAAB9adx97BU125.png "title=" 4.PNG " alt= "Wkiom1c9q73rhorhaab9adx97bu125.png"/> (2) Parameters related to user and user groups

-uid n : N is a number, this number is the user's account ID, which is the UID, this UID is recorded in the/etc/passwd with the account name corresponding to the number.

-gid n : N is a number, this number is the user's account ID, which is the GID, this UID is recorded in the/etc/group.

-user Name: Name is the username for the user account.

-group name : Name is the user group name.

-nouser : The person who is looking for the file owner does not exist in/etc/passwd.

-nogroup : All user groups looking for files do not exist in the/etc/passwd file.

When you install the software yourself, it is likely that the properties of the software do not have the file owner, this time you can use-nouser and

-nogroup to find it.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/51/wKiom1c9rT-DDqRiAABcfzLe3Ew086.png "title=" 5.PNG " alt= "Wkiom1c9rt-ddqriaabcfzle3ew086.png"/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/51/wKiom1c9rfSi4UOyAAAXBnMa78U361.png "title=" 6.PNG " alt= "Wkiom1c9rfsi4uoyaaaxbnma78u361.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/51/wKiom1c9rkmgTvA4AAAYXXCJrE0378.png "title=" 67.PNG "alt=" Wkiom1c9rkmgtva4aaayxxcjre0378.png "/>

(3) parameters that are related to file permissions and names

-name filename : Finds the file named filename.

-user : Finds files according to the owner of the file.

-group : finds files according to the group to which the files belong.

-size N [c] : Find files with a file length of n blocks, with C indicating the length of the file in bytes.

-size [+-]size : looks for files larger than size (+) or small (-). The sizes of this size are:

C Stands for byte

K for 1024bytes, to find a larger than 50KB file is "-size +50k".

-type : Find a file of a certain type, such as:

B-block device files.

D directory.

C-character device file.

P Pipeline file.

L Symbolic link file.

F Common Files.

P Pipeline file.

s socket.

-prune : Use this option to make the Find command not found in the currently specified directory, and if you use the-depth option at the same time,

-prune will be ignored by the Find command.

-perm : Finds files according to file permissions.

-perm mode : Find file permission "just equals" mode file, this mode file is similar to chmod property value, for example,-rwsr-xr-x property value is 4755.

-perm-mode : Find file Permissions "must have all mode permissions" of the file, for example, we want to find-rwxr--r--that is 0744 of the file, when a file-rwxr-xr-x permissions of 4755, will also be listed, Because the properties of the-rwsr-xr-x already include the properties of the-rwxr--r--.

-perm +mode : Find file Permissions "with mode permission" of the file, for example, we want to find-rwxr--r--is 0744 of the file, when a file-rwxr-xr-x permissions of 4755, will also be listed, Because the properties of the-rwxr-xr-x already include the properties of the-rwxr--r--.

-depth : When looking for a file, first find the file in the current directory, and then look in its subdirectories.

-fstype : Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.

-mount : Does not cross the file system mount point when locating files.

-follow : If the find command encounters a symbolic link file, it tracks to the file that the link points to.

-cpio : Use the cpio command for matching files to back up these files to the tape device.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/80/51/wKiom1c9rwrSbh7oAABQ50Pr71Q431.png "title=" 7.PNG " alt= "Wkiom1c9rwrsbh7oaabq50pr71q431.png"/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/51/wKiom1c9sgTC359TAACA-UTpyoY090.png "title=" 9.PNG " alt= "Wkiom1c9sgtc359taaca-utpyoy090.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/51/wKiom1c9s9vQTJUeAABJl8Rm3Pw945.png "title=" 12.PNG "alt=" Wkiom1c9s9vqtjueaabjl8rm3pw945.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/4F/wKioL1c9tbDAi1kdAABbRmQa878681.png "title=" 13.PNG "alt=" Wkiol1c9tbdai1kdaabbrmqa878681.png "/>650) this.width=650; src=" http://s4.51cto.com/wyfs02/M02/80/52/ Wkiom1c9tzvbnr_6aaarbmerfka909.png "title=" 14.PNG "alt=" Wkiom1c9tzvbnr_6aaarbmerfka909.png "/>

(4) Other possible operations

-print : Prints the results to the screen, which is the default action.

In the/logs directory, look for files that change time before 5th and delete them:

$ find Logs-type f-mtime +5-exec-ok rm {} \

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/52/wKiom1c9uZjSt1iNAAAlcAA8om0578.png "title=" 16.PNG "alt=" Wkiom1c9uzjst1inaaalcaa8om0578.png "/>

Third, the special function of find

The special function of find is to be able to perform additional actions (action).

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/4F/wKioL1c9v7iTc3uVAAA7ZgrNX1w161.png "title=" Capture 1. PNG "alt=" Wkiol1c9v7itc3uvaaa7zgrnx1w161.png "/>

Find not only can specify the directory to find (along with subdirectories), but can also use additional parameters to find the most correct file name.


If you are looking for a file with special attributes, such as suid, file owner, file size, etc., there is no way to use Locata, but find can be oh. Find can also use wildcard characters to find filenames. For example: To find out/etch The following file name contains httpd files, you can use the following command:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/52/wKiom1c9wK7QmsgpAABWPpF4z6E178.png "title=" Capture 5. PNG "alt=" Wkiom1c9wk7qmsgpaabwppf4z6e178.png "/>

Find profound, the other back to understand, for the time being said so many La La La.










This article is from the "stand out or Get out" blog, so be sure to keep this source http://jiazhenzhen.blog.51cto.com/10781724/1775182

File name Lookup command find

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.