Find command details and related examples

Source: Internet
Author: User

Find path-command parameters [output FORM]

Matching Criteria:

-name ' FILENAME ': exact matching of file masterpieces

File name wildcard:

*: Any character of any length

?: any single character

[]

-iname ' filename ': file name matching is case insensitive

-regex PATTERN: File name matching based on regular expressions

-user USERNAME: Based on owner Lookup

-group GROUPNAME: Search by Genus Group

-uid UID: Search by UID

-gid GID: Search by GID

-nouser: Finding files that are not owned by the master

-nogroup: Finding files that are not owned by a group

-type

F-Normal file.

D-Directory.

B-block device files.

C-character device file.

P-Pipeline file.

L-Symbolic link file.

S-socket file

-size [+|-]# to file size to find, #可以是K, M, G ask units

#k

#M

#G

Combination conditions:

-A with operation, add, requires 2 conditions at the same time to meet

- o or operation, or, to meet 1 conditions

-not non-arithmetic, not, take non-

Find by Time

-mtime

-ctime

-atime

[+|-]# + Represents #天之前-Represents #天之后

-mmin

-cmin

-amin

[+|-]# + Represents #分钟之前-Represents #分钟之后

-perm mode: Exact match (must be the same as specified by MODE)

/mode: Any one match that satisfies the condition (and the permission range specified by MODE has one of the same)

-mode: The file permission can fully contain this mode only when the condition is met (larger than the permission range represented by MODE)

MODE represents the file permission bits, such as 755, 644, and so on.

644:rw-r--r--

755:rwxr-xr-x

750:rwxr-x---

Find./-perl-001 represents a file that contains 001 permissions in the current directory.



Operation:

-exec COMMAND {} \;

-print: Display

-ls: Displays the details of each file in a form similar to Ls-l

-ok COMMAND {} \; User confirmation is required for each operation


Exercises:

1. How to find files larger than 10MB in the/usr directory?

Find/usr-size +10m


2. How do I find files that have been modified 120 days ago in the/home directory?

Find/home-mtime +120


3. How to find files that have not been accessed within 90 days in the/var directory?

Find/var \! -atime-90


4. Look for the file "core" under the entire directory tree, if found, without prompting to delete them directly.

Find/-name core-exec rm {} \;


5. Find all files in the/var directory under the master root and belong to the group mail;

Find/var-user Root-group Mail


6. Find files that do not belong to Root,bin or student in the/USR directory;

Find/usr-not-user root-a-not-user bin-a-not-user Student

Find/usr-not \ (-user root-o-user bin-o-user student \)


7. Find files that have been modified in the last week and not belonging to root and student users in/etc directory;

Find/etc-mtime-7-not \ (-user root-o-user student \)

Find/etc-mtime-7-not-user root-a-not-user Student



8, find the current system does not belong to the main or the group and the last 1 days have been visited the files, and the main group are modified to root;

Find/\ (-nouser-o-nogroup \)-a-atime-1-exec chown root:root {} \;


9. Find files larger than 1M in/etc directory and write their filenames to/tmp/etc.largefiles files;

Find/etc-size +1m >>/tmp/etc.largefiles


10, look for all the users in/etc directory do not have permission to write files, display its detailed information;

Find/etc-not-perm/222-ls


Find command details and related examples

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.