Linux (iii)----find

Source: Internet
Author: User

LinuxUnderFindcommand to search for a file in the directory structure and perform the specified action.
LinuxUnderFindCommands provide quite a lot of search criteria and are powerful. BecauseFind (NFS) ,find Commands are equally valid in the file system, and only you have the appropriate permissions. Running a very resource-intensive find when it comes to commands, many people tend to put it in the background, because traversing a very large file system can take a lot of time ( here refers to 30g )

1. Command format:

Find PATH [options][action]
2. Command function:
Used to locate files in the file tree and make appropriate processing (possibly accessing the disk)
3. Options and Parameters:

1. time-related options : Total-atime,-ctime,-mtime,-mtime as an example

-mtime N: = = number, meaning a file that has been changed in the [day] before n days;

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

-mtime-n: Lists the file names of the content that have been changed within n days (including the N-day itself);

-newer file:file for an existing file, listing a new file name than file;


Example 1:

#find/-mtime 0

0 means the current time, so, from now to 24 hours ago, have changed the contents of the file will be listed! If it is within 24 hours before three days, it is represented as # Find/-mtime 3

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/20/wKiom1c4c66T1RqsAABSB-uNb8k406.png "title=" QQ picture 20160515210332.png "alt=" Wkiom1c4c66t1rqsaabsb-unb8k406.png "/>

Example 2:

#find/etc-newer/etc/passwd

-newer is useful for distinguishing between the old and new relationships between two files!

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/20/wKiom1c4caLAms1OAABaAREiqnI292.png "title=" QQ picture 20160515205446.png "alt=" Wkiom1c4calams1oaabaareiqni292.png "/>


We now know the meaning of Atime, CTime, Mtime, if you want to find the name of a file that has been changed in a day, you can use Example 1, but what if I want to find out "file name changed in 4 days"? Then you can use "find/var-mtime-4". If it was "the Day 4 days ago", use "Find/var-mtime 4". There is no added "+,-" The difference is great! We can use a simple illustration to illustrate


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/1C/wKioL1c4WhCT_x8_AAAWEBLRx-E037.png "title=" QQ picture 20160514203749.png "alt=" Wkiol1c4whct_x8_aaaweblrx-e037.png "/>

The meaning of the time parameter for find correlation

The right side of the graph is the current time, and the farther to the left represents the earlier time axis. By the figure we can clearly know:
+ 4 represents a file name greater than or equal to 5 days ago:ex> find/var-mtime +4
-4 for file names less than or equal to 4 days:ex> find/var-mtime-4
4 is the 4-5 day file name:ex> find/var-mtime 4


2. Parameters related to the user or group name:

-uid-N is a number, which is the user's account ID, the UID,

This UID is the number that is recorded in the/etc/passwd and corresponds to the account name.

-gid-N is a number, which is the ID of the group name, the GID,

This GID is recorded in/etc/group.

-UESR name:name as user account name

-group Name:name for Group name

-nouser: The person who finds the owner of the file does not exist/etc/passwd

-nogroup: There is no file with/etc/group for the owning group looking for the file

When you install the software yourself, it is possible to change the properties of the software and the owner of the file, which is possible! At this time, you can use-nouser and-nogroup to search.

Example 3:

#find/home-user Zyn

Search for files belonging to Zyn under/home

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/1D/wKioL1c4cxSx-OGSAABTsk1i1dI430.png "title=" QQ picture 20160515205703.png "alt=" Wkiol1c4cxsx-ogsaabtsk1i1di430.png "/>

Example 4:

#find/-nouser

Find files that the system doesn't belong to anyone.

If you delete an account in the system, but the account has been in the system to create a lot of files, there may be no master ghost of the file, you can use-nouser to find the type of file and deleted.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/1D/wKioL1c4dFPSK9pGAAArzlQpmDc787.png "title=" QQ picture 20160515210230.png "alt=" Wkiol1c4dfpsk9pgaaarzlqpmdc787.png "/>

3. parameters related to file permissions and names:

-Name filename: search for files named filename;

-size [-+] Size: Search for files larger or smaller than size, this size has: C for Byte, K for 1024bytes, so, to find than 50KB to fight File, is [-size + 50K];

-type type: Types of search files, types are: General regular archives (f), device files (b,c), directories (d), connection files (l), Scoket (s), and FIFO (p) and other properties.

-perm Mode: Search file permission "just equals" mode file, this mode is similar to the chmod attribute value, for example:-rwsr-xr-x, that is, 4755,

-perm-mode: Search file Permissions "must all include Mode's permission" file, for example: to search

                          - Rwxr--r--, that is 0744 of the file, using-perm-0744, when a file's permission is

 -rwsr-xr-x have been included in the

-perm +mode: Search file Permissions "include arbitrary mode Permissions" of the file, for example: Search-rwxr-xr-x, that is,-perm +755, but a file property is-RW------- will also be listed because he has-rw-------attributes exist!

Example 5:

#find/-name passwd

Find this file named passwd.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/20/wKiom1c4czzjbb_3AAAo9FrHduI181.png "title=" QQ picture 20160515210140.png "alt=" Wkiom1c4czzjbb_3aaao9frhdui181.png "/>

Example 6:

#find/var-type S

Find out which file type is scoket under the/var directory?

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/1D/wKioL1c4dQjgyprkAABc3wnbZUM341.png "title=" QQ picture 20160515210424.png "alt=" Wkiol1c4dqjgyprkaabc3wnbzum341.png "/>

Example 7:

#find/-perm +7000

Search for files that contain suid or SGID or Sbit attributes

The so-called 7000 is---s--s--t, then as long as the S or T is listed, 7000 is to contain---s--s--t three permissions

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/20/wKiom1c4dBjzcTDkAABa9yqidbQ025.png "title=" QQ picture 20160515210519.png "alt=" Wkiom1c4dbjzctdkaaba9yqidbq025.png "/>

4. additional actions to be performed :

-exec Command:command For other instructions, the-exec can then be followed by additional instructions to process the results of the search.

-print: Print the results to the screen, this action is a preset action!

Example 8:

#find/-perm +7000-exec ls-l{} \;

The files found in the previous example are listed using Ls-l.

Ls-l is an extra instruction, the instruction does not support command aliases, so you cannot use LL

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/80/20/wKiom1c4dILhRwO7AACGU6NwaIY878.png "title=" QQ picture 20160515210703.png "alt=" Wkiom1c4dilhrwo7aacgu6nwaiy878.png "/>

Example 9:

#find/-size +1000k

Find files that are larger than 1MB

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/1D/wKioL1c4dZjAloyoAAB3zFZKnY8319.png "title=" QQ picture 20160515210755.png "alt=" Wkiol1c4dzjaloyoaab3zfzkny8319.png "/>

The special function of find is to be able to carry out additional actions (action), we will use example 8 to illustrate;

650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/80/20/wKiom1c4bkvz5f2OAAAQI9u B3zu598.png "title=" qq picture 20160515200948.png "alt=" Wkiom1c4bkvz5f2oaaaqi9ub3zu598.png "/>

{} represents the content found with find, as shown in, the find result is placed in the {} position

-exec always to \; Is the keyword that represents the start of the Find extra action (-exec) to the end (\;), and in this middle is the extra action in the Find command, which in this case is "ls-l{}".

Because ";" has a special meaning under bash, so use a backslash to jump off.







Linux (iii)----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.