"Linux" Linux system Find instructions detailed usage and examples

Source: Internet
Author: User

The Find command in Linux is one of the most important and great commands in the Linux system and is very powerful. I'll share the find command with the example code below. Since I can't post the Linux code on my blog, I've shown the code and the effects in it.


I first created the file name of the test.c normal file, we use the instruction mkdir, and LS view has created test.c.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/48/wKioL1c9VzyQalhuAAAktKIMzNs034.png "title=" Vb0t7h45yv$]ha5[n[9j ($C. png "alt=" Wkiol1c9vzyqalhuaaaktkimzns034.png "/>

Now we look for it.

    1. Find by filename or regular expression:-name by file name


      Filename:

1) find./-name test.c look for files with file name test.c


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/48/wKioL1c9Wu2gJl51AAALFDsmLSE107.png "title=" Find1.png "alt=" Wkiol1c9wu2gjl51aaalfdsmlse107.png "/>

2) Find. /-name ' test.c* ' find file name including test


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/4B/wKiom1c9WkOzC_tWAAAZw3fcmqk534.png "title=" Find2.png "alt=" Wkiom1c9wkozc_twaaazw3fcmqk534.png "/>


Regular Expressions:

1) Find with "! "To negate the argument.

Find./! -name ' *.c '-print find file names that are not. C and print them out. (The actual rear-print can be not, the effect will be displayed on the screen)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/49/wKioL1c9XnrxDwa7AAB4Y2QnZuA829.png "title=" Find3.png "alt=" Wkiol1c9xnrxdwa7aab4y2qnzua829.png "/>

2) If you want to match one of several conditions, you can use the-o parameter.

-A with conditions

-O or condition

-not Non-conditional (this parameter functions like a negative argument '! ') )



2. Search by File size

The-size option allows you to find files by file size.

-size N:[c] finds files with a file length of n blocks, with C indicating the length of the file in bytes.

b--block (512 bytes); c--byte; w--Word (2 bytes);

k--kilobytes; m--megabytes; g--gigabytes.


1) Find ~-size +100k look for files larger than 100k

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/49/wKioL1c9YvjjLTFCAAAVgOP8DQc509.png "title=" Fing4.png "alt=" Wkiol1c9yvjjltfcaaavgop8dqc509.png "/>

2) Find ~-size-100k look for files smaller than 100k

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/4C/wKiom1c9YhyxTymWAABrg5hdAcI502.png "title=" Find5.png "alt=" Wkiom1c9yhyxtymwaabrg5hdaci502.png "/>

3) Find ~-size 100k looking for files of size 100k

Note: – refers to smaller than a given size, + refers to larger than a given size. No symbol represents exactly as large as the given size.


3. Search by File depth

Searches the depth of the specified directory using the mimdepth,maxdepth limit.

-depth: When looking for a file, first find the file in the current directory and then look it up in its subdirectories.


1) Find./-name Test Locate a file named Test in the root directory and subdirectories

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/4A/wKioL1c9af7AudgsAAAPLXaqRhg981.png "title=" Find9.png "alt=" Wkiol1c9af7audgsaaaplxaqrhg981.png "/>

2) find-maxdepth 2-name Test Find a file named Test in the root directory and a subdirectory with a depth of 1

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/4A/wKioL1c9aC3xvGzpAAAPMZc2DNc501.png "title=" Find6.png "alt=" Wkiol1c9ac3xvgzpaaapmzc2dnc501.png "/>


3) find-mindepth 1-maxdepth-name test finds a file named Test in a subdirectory with a depth of 0 and a subdirectory of depth 5

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/4C/wKiom1c9aGmTrq7-AAARYq_j2ao837.png "title=" Find8.png "alt=" Wkiom1c9agmtrq7-aaaryq_j2ao837.png "/>

4. Find files based on file permissions

-perm to find files according to the permissions of the file.

1) find-perm-g=w find a file with group Read permission

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/4D/wKiom1c9bubDc_RwAADkNK7Fbqg836.png "title=" Find11.png "alt=" Wkiom1c9bubdc_rwaadknk7fbqg836.png "/>


5. Find files based on file type.

-type find a file of a certain type. Such as:

File Type type parameter
Normal file F
Symbol File L
Catalog D
Character Device C
Block Device B
Socket s
Pipe file P


1)find. -typed 查找类型为目录的文件

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/4B/wKioL1c9coPxhfFbAABTODTp5Z8208.png "title=" Find12.png "alt=" Wkiol1c9copxhffbaabtodtp5z8208.png "/>


其他类型的文件就可以按照上述命令来查找了。


6. Search by file time

Each file in the Linux file system has three timestamps

Access Time (-atime): The last time a user accessed a file;

Modification Time (-mtime): The time the file content was last modified.

Change Time (-ctime): The time the file metadata (metadata, such as permissions or ownership) was last changed.

-atime,-mtime,-ctime as the time parameter, the unit is day. You can use + to represent greater than,-represent less than (and the same as +,-based on file size lookups).

1) Find./-mtime-5 finds files that have been modified less than or equal to 5 days


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/4E/wKiom1c9deeiV2wVAABTnuYfgqA398.png "title=" Find14.png "alt=" Wkiom1c9deeiv2wvaabtnuyfgqa398.png "/>


2) find./-mtime +2 Find files that have been modified more than 2 days ago

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/4E/wKiom1c9dkbhjf-dAAB0Bg_Ul0s983.png "title=" Fing15.png "alt=" Wkiom1c9dkbhjf-daab0bg_ul0s983.png "/>

3) Find/-mtime 1 find 1 days ago, modified file of the day

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/80/4B/wKioL1c9d4nhZULdAAAeTgnMfT4610.png "title=" Find16.png "alt=" Wkiol1c9d4nhzuldaaaetgnmft4610.png "/>

4) Find/-newer test.c find a new file than test.c

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/4B/wKioL1c9d83COArJAADGvEZqJ_0051.png "title=" Find17.png "alt=" Wkiol1c9d83coarjaadgvezqj_0051.png "/>


This article is from "Han Jing's Blog", please make sure to keep this source http://10740184.blog.51cto.com/10730184/1775088

"Linux" Linux system Find instructions detailed usage and examples

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.