Linux command: Find file Find tool locate command lookup

Source: Internet
Author: User

Find Introduction to Commands:    

Real-time, accurate, and support for many search criteria

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

1 . Command format:

Locate filename directly with the file you need to find eg locate passwd System file database all

The file that contains the passwd.

Find Find Path Lookup criteria finds a later processing action

Find path: Default to current directory

Lookup criteria: Default to all files under the specified path

Handling actions: Default to display on screen

Eg:find/etc-name passwd means to find a file named passwd in the ETC directory

2 . Command function:

Locate: (Find command)

Non-real-time, fuzzy matching, lookup is based on the system-wide file database;

# UpdateDB, manually generate the file database

Fast speed

Find

Realtime

Accurate

Support for many search criteria

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

3 . Command parameters:

-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 Find/tmp-type D Find the directory file under/TMP including/TMP itself

F: Normal file

D: Catalog file

C: Character device file

B: Block device files

L: Link File

P: Piping Equipment files

S: Socket device file

-size [+|-] +10k indicates files greater than 10k -10k represent files less than 10k

Find/tmp-size 10k Indicates a file size of 10k under/TMP is found

Default unit is not specified, byte b

1k all less than 1k will be matched to, 1M all less than 1M will be matched to

#k k=kb #表示数字 k to lowercase

#M m=mb #表示数字 M Capital

#G G=GB #表示数字 G caps

Combination condition: If you do not specify a composition relationship when you find it, the default is the relationship

Find/tmp-nouser-a-type D-ls

Find/tmp-not-type d Find files that are not directories

-A: With

-O: Or

-not: Non-

Eg: look for a file that is not in the/tmp directory, is not a directory, and cannot be a socket type;

Find/tmp-not-type D-a-not-type S

eg: Find /tmp/test Directory, the owner is not user1, nor user2 files;

Find/tmp-not-user user1-a-not-user User2

* Equivalent to Find/tmp-not \ (-user user1-o-user user2 \)

* Keep in mind that space is required to separate

calculated by Time:

-mtime modification Time

-ctime Change Time

-atime Access Time

[+|-]# #表示数字 +5 means more than 5 days-5 means within five days

by number of minutes:

-mmin

-cmin

-amin

[+|-]# #表示数字 +5 means more than 5 minutes-5 means within 5 minutes

-perm MODE: Exact match-perm 644 means exact match, must be 644 permissions

/mode: Any one match that satisfies the condition-perm/644 means that as long as there is a match, you can

-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/022 indicates that a group or other person has write permission 0 to not make a match.

Find/-perm-001 Finding files with Execute permissions for other users

Action:

-print: Display (-print is also the default action, that is, do not specify the action is displayed by default)

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

-ok COMMAND {} \; Each operation requires the user to confirm that {} refers to the file found earlier

-exec COMMAND {} \;  no user confirmation required for each operation {} means reference to the file found earlier

Find./-type D-ok chmod +x {} \; Indicates that a directory file is found and given execute permissions

Find./-perm-020-ok mv {} {}.new \; Locate the file with the Write permission for the subordinate group in the current directory and modify its file name to the original file. New.

4 . Command instance:

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

Find/var-user root-a-group Mail

[Email protected] test]# Find/var-user root-a-group Mail

/var/spool/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

or find/usr-not \ (-user root-o-user bin-o-user student \) Parentheses must have spaces around

[[email protected] usr]# find/usr-not \ (-user root-o-user bin-o-user student \)

/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

[Email protected] usr]# find/usr-not-user root-a-not-user bin-a-not-user Student

/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache


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-a-not \ (-user root-o-user student \)

or find/etc-mtime-7-a-not-user root-a-not-user Student


4. Find files on the current system that are not owned by the master or group and have been visited in the last 1 days, and

The genus Group is changed 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

[Email protected] ~]# find/etc-size +1m >>/tmp/etc.largefiles

[Email protected] ~]# Cat/tmp/etc.largefiles

/etc/selinux/targeted/modules/active/policy.kern

/etc/selinux/targeted/policy/policy.24

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

[Email protected] ~]# Find/etc-not-perm/222-ls

493 4-r--r-----1 root root 4002 March 2 2012/etc/sudoers

2279 4----------1 root root 2541 October 23:10/etc/shadow

960 4-r--r--r--1 root root 460 August 2013/etc/dbus-1/system.d/cups.conf

523 172-r--r--r--1 root root 172980 October 08:25/etc/pki/ca-trust/extracted/java/cacerts

519 308-r--r--r--1 root root 314336 October 08:24/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt

521 184-r--r--r--1 root root 185220 October 08:25/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem

520 228-r--r--r--1 root root 232342 October 08:24/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

522 184-r--r--r--1 root root 185023 October 08:25/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem

4----------1 root root 2415 October 23:10/etc/shadow-

4----------1 root root 829 October 23:10/etc/gshadow-

1091 4-r-xr-xr-x 1 root root 2134 November 2013/etc/rc.d/init.d/lvm2-lvmetad

1092 4-r-xr-xr-x 1 root root 2665 November 2013/etc/rc.d/init.d/lvm2-monitor

1090 4-r-xr-xr-x 1 root root 1340 November 2013/etc/rc.d/init.d/blk-availability

129 4----------1 root root 841 October 23:10/etc/gshadow

1149 4-r--r--r--1 root root 324 November 2013/etc/ld.so.conf.d/kernel-2.6.32-431.el6.i686.conf

962 4-r--r--r--1 root root 146 August 2013/etc/pam.d/cups


This article is from the "Learn Linux history" blog, please be sure to keep this source http://woyaoxuelinux.blog.51cto.com/5663865/1865216

Linux command: Find file Find tool locate command lookup

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.