Linux File Search

Source: Internet
Author: User

Grep,egrep,fgrep: Text lookup (content in a text file)


File Lookup:

Locate:

System-wide Search commands,

Not real-time,

Fuzzy matching

Lookup is based on a system-wide file database

#updatedb, manually generate the file database because the new system may not have a file database established

Fast speed


Find:

Real-time Search

Exact search

Support for many search criteria

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


Usage:

Find Find Path Lookup criteria lookup to future processing operations

Find path: Default to current directory

Lookup criteria: Default to all files under the specified path

Processing operation: Default is Display


Matching Criteria:

-name ' FILENAME ': do the file name Exact Match

File name wildcard:

*: Any character of any length

? : any single character

[]: characters within the range

-iname ' FILENAME ': file name matching Case insensitive

-regex PATTERN: based on Regular Expressions to match file names


-user USERNAME: according to Owner Find

-group GROUPNAME: according to Genus Group Find


-uid UID : according to UID Find

-gid GID: according to GID Find


-nouser: Find No master of the file

-nogroup: Find No group of the file


-type

F: Normal file

D: Catalogue

C: Character device file

B: Block device files

L: Link File

P: Pipeline File

S: Socket file


-size

[+|-] #k

[+|-] #M

[+|-] #G


Combination conditions:

-A: with (and)

-O: or (OR)

-not: Non-


Find files in the/tmp directory, not directories, and cannot yet be socket types

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

Find/tmp-not \ (-type d-o-type s \)

Find the/tmp/test directory, the owner is not user1, nor user2 files;

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

Find/tmp/test-not \ (-user user1-o-user user2 \)



parameters about timestamps:

-mtime

-ctime

-atime

[+|-]#

-mmin

-cmin

-amin

[+|-]#


about the parameters of the permission

-perm

MODE: Exact Match

/mode: any one match that satisfies the condition

-mode: File permissions can when fully containing this mode to display


Find./-perm-644


-644

644:rw-r--r--

755:rwxr-xr-x


Operation:

-print: Show

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

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

-exec Commond {} \; No user confirmation required


# Find-type D-ok chmod a-x {} \;

# Find./-perm-020-exec mv {} {}.new \;

# Find/-name "*.sh"-a-perm-111-exec chmod o-x {} \;



the practice of the Find command:

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


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-a-not \ (-user root-o-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 {} \;


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

# find/etc-size +1m-print >>/tmp/etc.largefiles


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

# Find/tmp/test-not-perm/222-ls


Linux File Search

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.