Linux Basics (13) Text Finder How to use the Find tool

Source: Internet
Author: User
Tags file permissions

Find (locate because of the need to update the database, so not very common) is a very powerful Linux file Search command, with the following characteristics.

1. Real-time, new files can be found immediately

2. Precise

3. Support many search criteria, based on user's owner, permission, group, timestamp to find.

4. Traverse all files in the specified directory to complete the lookup, slower.


Syntax rules for find:

Find find path Find condition finds to future processing operation

Find path: Default to current directory

Find condition: defaults to all files under the specified path

Processing operation: Default to show results after lookup

###################################################################

Search criteria:

-name ' FILENAME ': exact matching of file masterpieces

File name wildcard:

*: Any character of any length

?

[]

-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: Catalogue

C: Character device file

B: Block device files

L: Link File

P: Pipeline File

S: Socket file

-size [+|-] #按照文件的大小进行查找 plus sign represents greater than, minus sign is less than

#k KB

#M MB

#G GB

Find criteria can be combined

-A logic and

-O Logic or

-not Logical Non-


-mtime file was modified #按照时间戳进行查找

Change time of-ctime file

Access time for-atime files

[+|-]# the plus sign represents a time before the minus sign represents a certain time, the unit is the default day

For example, + 1 represents a day, 1 represents a day or less

-perm MODE: Exact match

/mode: Any one match that satisfies the condition

-mode: File permissions can fully contain this MODE only when the condition is met

-644

644:rw-r--r--

755:rwxr-xr-x

750:rwxr-x---

Find./-perm-001

##############################################################################

Find finished processing operations

Operation:

-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

-exec command {} \; #注意, followed by \; cannot be omitted, represents the end of an order. and \; There is a space between {}.

############################################################################

Here are a few examples:

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

Find/var-user Root-group Mail


2. 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 \)


3. 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



4, 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 {} \;


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

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


6, 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


This article is from the "thick Product Thin Hair" blog, please make sure to keep this source http://joedlut.blog.51cto.com/6570198/1826592

Linux Basic (13) Text Find tool how to use Find

Related Article

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.