Use of Find

Source: Internet
Author: User

Format of the Find command: Find [-path]-options [-print-exec-ok]

Path
: The directory path to find.
~ Represents the $home directory
. Indicates the current directory
/represents the root directory
-print: Indicates output of the result to standard output
-exec: Executes the shell command given by the parameter to the matching file. The form is command {} \; , note {} and \; There are spaces between
-ok: As with-exec, the difference is that a prompt is given before the command is executed to let the user confirm whether
the

options are commonly used with the following option:
-name Search by name
-perm Install permissions find
-prune no longer found under the currently specified directory
-user File owner to
find-group belongs to group to find
-nogroup find files with no valid owning group
-nouser Find files
with no valid owner -type Search by file type

Here are some simple examples to illustrate the general use of the next find:

1. Search by name

In the current directory and subdirectories, find the TXT file at the beginning of the capital letter

    1. [[email protected] ~]# find. -name ' [A-z]*.txt '-print


In/etc and its subdirectories, look for files at the beginning of host

    1. [Email protected] ~]# find/etc-name ' host* '-print


In the $home directory and its subdirectories, find all Files

    1. [[email protected] ~]# Find ~-name ' * '-print

In the current directory and subdirectories, find the TXT file that is not the beginning of the out

    1. [email protected]. code]# Find. -name "out*"-prune-o-name "*.txt"-print

2. Search by directory

Search for txt files in subdirectories other than AA in the current directory

    1. [email protected]. code]# Find. -path "./aa"-prune-o-name "*.txt"-print


Find txt files in the current directory and subdirectories other than AA and BB

  1. [email protected]. code]# Find.−PATH"./Aa"−o−patH". /bB" -prune-o-name "*.txt"-print


In the current directory, no longer subdirectories, find txt files

    1. [email protected]. code]# Find. ! -name "."-type d-prune-o-type f-name "*.txt"-print

3. Search by permissions

In the current directory and subdirectories, look for the master with read and write execution, and other files with reading Execute permission

    1. [[email protected] ~]# find. -perm 755-print


4. Search by Type

In the current directory and subdirectories, locate the symbolic link file

    1. [email protected]. code]# Find. -type L-print


5. According to the owner and genus Group

Find files that belong to www

    1. [email protected]. code]# Find/-user www-type F-print


Find files that belong to the main deleted

    1. [email protected]. code]# Find/-nouser-type F-print


Find files belonging to the group MySQL

    1. [[Email protected]lhost. code]# Find/-group mysql-type F-print


Find files deleted by user group

    1. [email protected]. code]# Find/-nogroup-type F-print


6. Search by Time

Find files that have been changed in 2 days

    1. [email protected]. code]# Find. -mtime-2-type F-print


Find files that have been changed 2 days ago

    1. [email protected]. code]# Find. -mtime +2-type F-print


Find files that are accessed in a day

    1. [email protected]. code]# Find. -atime-1-type F-print


Find files that were accessed a day ago

    1. [email protected]. code]# Find. -atime +1-type F-print


Find files that are changed in the day

    1. [email protected]. code]# Find. -ctime-1-type F-print


Find a day ago state changed file

    1. [email protected]. code]# Find. -ctime +1-type F-print


Find files with status changed 10 minutes ago

    1. [email protected]. code]# Find. -cmin +10-type F-print


7, according to the old and new documents

Find a new file than Aa.txt

    1. [email protected]. code]# Find. -newer "Aa.txt"-type f-print


Look for older files than Aa.txt

[Plain]View PlainCopy
    1. [email protected]. code]# Find. ! -newer "Aa.txt"-type f-print


Find newer than aa.txt, older than bb.txt files

    1. [email protected]. code]# Find. -newer ' Aa.txt '! -newer ' Bb.txt '-type f-print


8. Search by size

Find files that are over 1M

    1. [email protected]. code]# Find/-size +1m-type F-print


Find files that are equal to 6 bytes

    1. [email protected]. code]# Find. -size 6c-print


Find files that are less than 32k

    1. [email protected]. code]# Find. -size-32k-print


9. Execution of Orders

Find Del.txt and delete, prompt confirmation before deleting

    1. [email protected]. code]# Find. -name ' Del.txt '-ok rm {} \;


Find Aa.txt and back up as Aa.txt.bak

    1. [email protected]. code]# Find. -name ' Aa.txt '-exec cp {} {}.bak \;

Find Aa.txt Archive compressed to aa.txt.tar.gz and remove Aa.txt

      1. Find. -name "Aa.txt"-type f-exec tar-zcvf {}.tar.gz {} \; -exec RM-RF {} \; >/dev/null

Use of Find

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.