File find-locate Find learning Notes

Source: Internet
Author: User

Locate: (FAST)

Non-real-time, fuzzy matching. Lookup is based on a system-wide database

#updatedb manually generating a file database

Find: (Slow speed)

Real-time lookup,

Exact Search,

Support for many search criteria

Traverse all files in the specified directory to complete the lookup,

Find Find Path Lookup criteria lookup to future processing operations

Find path: Default current directory

Lookup criteria: Default to all files under the specified path

Processing operation: Default is Display

Matching Criteria:

-name ' filename ': Exact Match of file name

File name wildcard:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/84/08/wKioL1eEFy2hLWJ4AABrgXSwqs8040.png "title=" Shell common wildcard characters. png "alt=" Wkiol1eefy2hlwj4aabrgxswqs8040.png "/>

-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: Search by file type

F: Normal file

D: Catalogue

C: Character device

B: Block device

L: Connection File

P: Piping Equipment

S: Socket device

-size: Search by File size

[+|-] #k

#M

#G

-10k all files less than 10k

+10k all files larger than 10k

Combination conditions:

-A: With

-O: Or

-not: Non-


[[email protected] ~]# find /etc -name  ' passwd '           #在  /etc  directory to find files with file name  passwd  [[Email protected] ~]# find  /etc -name  ' passwd* '        find file names under #在  /etc  directory  passwd   Opening file [[email protected] ~]# find /tmp -user zhao               #在  /tmp  directories to find files in the main  zhao  file [email  protected] ~]# find /etc -group mysql            #在  /etc  directories to find files belonging to a group  mysql  [[Email protected] ~]# find  /etc -type d                     find a directory under #在  /etc  directory [[email protected] ~]# find / Etc -size 1m                  #在  / etc  directory Find files of size  1M  (all files in  1M ) [[Email protected] ~]# find /etc  -size 10k -ls              #在  /etc  directory to find all files within  10k , and long format display [[email protected] ~]# find /etc - nouser -a -type d    in #在  /etc  directory [[email protected] with no owner and type directory  ~]# find /etc -not -type d              find non-directory files under #在  /etc  directory [[email protected] ~]# find /tmp  -not -type d -a -not -type s    #/tmp  directories, not directories, and cannot be a socket type file


Find files based on time stamp

-mtime: Modification Time (days)

-ctime: Change Time

-atime: Access Time

[ +|- ]#

-mmin

-cmin

-amin

[ +|- ]#


[[email protected] etc]# Find/-amin-5 #查找当前目录下, files accessed within 5 minutes [[email protected] etc]# find./-amin +5 #查找当前目录下, 5 minutes Previously accessed files (at least 5 minutes have not been visited)



-perm chmod based on file permissions match

-perm # # #: Exact match

-perm/###: Any one match succeeds

-perm-###: File permissions can only be displayed when this MODE is fully contained (three-bit fully included)

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s4.51cto.com/wyfs02/m02/84/09/wkiom1eegolay1l3aady4v09ggi706.png "title="-perm.png "alt=" Wkiom1eegolay1l3aady4v09ggi706.png "/>

Action:

-print: Display

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

-ok COMMAND {} \: User confirmation required

-exec COMMAND

[[email protected] etc]# Find/-perm-006-exec chmod o-w {} \; #在当前目录下找到 Other people permissions include RW files, and will find the file that cancels W permission.    {} is a placeholder [[email protected] etc]# find./-perm-020-exec mv {} {}.new \;   #在当前目录下找到 Group of files that contain W permissions and rename them to. New[[email protected] etc]# fidn./-name "*.sh"-a-perm-111-exec chmod o-x {} \; #在当前目录下找到. Sh end file, and there are files for which the other person in the main group has EXECUTE permission, minus the Execute permission



Practice:

1. Find all files in the/var directory that are subordinate to root and belong to the group mail;

Find/var-user Root-group Mail

2. Find files that do not belong to the root bin 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 over the last week in the/etc directory and are not root and student users;

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

4. Find files on the current system that are not owned by the owner or group and have been visited in the last day, and change their genus to root;

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

5. Find the file with heavy rain 1M in/etc directory and write its file name to the/tmp/etc.largefile file;

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

6. Find files with no write permission for all users in/etc directory, display their details

Find/etc-not-perm/222-ls






File find-locate Find learning Notes

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.