Linux_find File Lookup command

Source: Internet
Author: User

File Lookup:

Locate, non-real-time lookup, search in the temporary database, fuzzy matching.

[[Email protected] ~]# Locate passwd Find out if the current system has passwd this file

Updatede manually generating a staging database

Advantages: Fast speed and low resource consumption

Find: Real-time find, exact lookup, traverse all files in the specified directory, slow. Support for many search criteria. Support for regular Expressions

format:find Find path find criteria lookup to future processing action

Omitting the lookup path, the default is that the current directory

Omit lookup criteria, default to all files under the specified path

Handling actions: Default to show

Match criteria:-name exact Search by file name

[[Email protected]~]# find/etc-name ' passwd ' find out if there is passwd this file under etc

file name wildcard:

? matches any single character in the file name.

[...] Match any characters that are contained in [].

[!...] Match [] Central African exclamation point! The character after.

* matches any string in the file name, including an empty string.

Such as:

5* 5 All strings starting with

*5 5 end of all strings

*5? a string with a second- to -last character of 5

[0-9] all characters with numbers

[1] or 2

[!0-9] characters that are not numbers

[[email protected] ~]# find/etc-name ' passwd* ' find All files beginning with etc under passwd

[[email protected] ~]# find/etc-name ' *passwd ' find All files under etc passwd end

[[email protected] ~]# find/etc-name ' *passwd* ' find All files of etc under name including passwd

-iname file name matching is case insensitive

-regex PATTERN for file name matching based on regular expressions

-user Search based on the owner of the file

[[email protected] ~]# find/tmp-user root find files under tmp that belong to root

-group Search by genus Group

-uid based on uid lookup

-gid based on gid search

-nouser finding files that are not owned by the master

[[email protected] ~]# find/tmp–nouser find files that are not owned by TMP

-nogroup finding files that are not owned by a group

-type Search by file type

F Common Files

Catalog D

C- character device

B- block equipment

L Link File

P Piping Equipment

s socket file

[[email protected] ~]# Find/tmp-type d find directory under tmp

[[email protected] ~]# find/tmp-type s find socket file under tmp

-size Specifies the size of the lookup file

[+|-] #K

#M

[[email protected] ~]# find/etc/-size 1m–ls find files under etc 1M or near 1M . and execute LS

[[email protected] ~]# find/etc/-size-1m–ls find all files under etc below 1M and execute ls

[[email protected] ~]# find/etc/-size +1m–ls find All files larger than 1M in etc and execute LS

#G

Combination conditions:

-A and

-O or

-not Non-

The default is with the action

[[email protected] ~]# Find/tmp-nouser–a-type d find files that are not owned by TMP and have a file type of directory

[[email protected] ~]# Find/tmp-nouser-o-type d look for a file that does not belong to the master or file type directory under tmp

[[email protected] ~]# Find/tmp-not-type d find a non-directory file under tmp

1. Find a file with TMP that is not a directory or a socket file

[Email protected] ~]# Find/tmp-not-type d-o-not-type s

2. find the current file under the owner is neither user1 nor user2 file

[[email protected] ~]# Find/-not-user user1-a-not-user user2

[[email protected] ~]# Find/-not \ (-user user2-o-user user1 \)

3. find files in the current directory that are not User1 or type is not a directory

[[email protected] tmp]# find./-not-user User1-o-not-type D

[[email protected] tmp]# Find/-not \ (-user user1-a-not-type d \)

-mtime The most recent creation time , how many days

-ctime last time to change

-atime last access time

[+|-]# + means no visit for at least a few days

-5 means no access within 5 days.

5 means just 5 days without a visit

-mmin How many minutes

-cmin

-amin

[+|-]#

[[Email protected]~]# find/tmp-amin +5 find files that have not been accessed for at least 5 minutes under TMP, or files that were accessed 5 minutes ago

[[email protected] ~]# find/tmp-atime +7 find files that have not been accessed for at least 7 days under TMP

-perm MODE based on file permissions, default to exact match,9 -bit permissions must match

[[Email protected]~]# find/tmp-perm 755-ls find files with a file permission of TMP under 755 and display

-perm–mode contains a file thatmatches 9 -bit permissions , columns such as Find 644 permissions, 755 also appears, as long as the permission contains 9 of the 644 Bit permissions can be found

1 -bit match in-perm/mode9-bit permission

[[Email protected]~]# find/tmp-perm/755-ls look up tmp under 9 permissions that have a permission to match to the file

find under Current file files with Execute permissions for other users

[Email protected]~]# find./-perm-001

Action:

-print: Display

-ls: A similar ls-l -like form showing each matching detail file

-ok COMMAND {} \; -ok will let the user confirm each operation . {} indicates the file to which the reference was found

-exec COMMAND {} \;

[Email protected]~]# Find/-perm-006-exec chmod o-w {} \; find files in the current directory where other users have read and write permissions and remove Write permissions

[Email protected]~]# find./-type d-exec chmod +x {} \; Locate the file under the current file for the directory and take the owner, belong to the group of other users all plus Execute permissions

[[Email protected]~]# find./-perm-020-exec mv {} {}.new \; Locate the file under which the current file group has Write permission and change its name to the original name plus . New

find the file named . SH at the end of the current directory and all users have permission to execute files, and then remove other users ' Execute permissions

[[Email protected]~]# find]/-name "*.sh"-a-perm-111-exec chmod o-x {} \;

1. Find All files in the /var directory that are subordinate to the root and belong to the group Mail

[[email protected] ~]# find/var-user ' root '-a-group ' mail '

2. Find files that do not belong to Root,bin or student in the /usr directory

[[email protected] ~]# find/usr-not-user ' root '-a-not-user ' bin '-a-not-user ' student '

3. find files in/etc that have been modified in the last week and not owned by Root and student users

[[email protected] ~]# Find/-ctime-7-a-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 content has been accessed the file, and the owner of the group is changed to root

[[email protected] ~]# Find/\ (-nouser-o-nogroup \)-a-atime-1-exec chown root:root {} \;

5. Find files larger than 1M in the/etc directory and write their filenames to the/tmp/etc.largefile file

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

[[email protected] tmp]# find/etc-size+1m-exec echo {} >>/tmp/etc.largefiles \;

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

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

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

Xargs: no placeholder {} , nor need \ . But you need a pipe | put it in front of Xargs


This article from "Linux operation and Maintenance" blog, declined reprint!

Linux_find File Lookup command

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.