Summary of the usage of the Find command under Linux Linux

Source: Internet
Author: User
Tags tmp file

Objective:

Why do you want to study him before we explain what the next Find command is?

The Find command is a very important operation for Linux, because Linux is a "everything file" operating system, the find (Find files) directive is particularly important, under the Windows operating system, we find a file can be directly on the computer to search for files, But Linux operating system files are not suffix, similarly, the Find function under Linux is relative to Windows, a lot more powerful.


There are several search commands under Linux, we mainly talk about the locate and find two instructions .


The locate directive is a traversal of the database it generates (the command that generates the database (UpdateDB)). This feature determines the speed of finding files with locate, so if the locate speed can be found quickly, then why do you need a find command? Because the locate directive only blurs the file, the accuracy is not very high.

#locate的简单操作选项:

-I//file is not case-sensitive when looking for example: Locate-i tmp

-N//show only the first n rows of the search results for example: Locate-n 5 t


Let's cut to the chase:

A summary of the use of the Find directive:

    1. Match Search by file name or regular expression


(1), search by file name

Operation Options:-name

Operation Example: First look at our current directory using the PWD directive, then mkdir a file in the current directory tmp, and then use find./-name tmp command to find the TMP file, use Find ./-name ' tmp* ' to find all files that contain TMP.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/5B/wKiom1c-fRfwLewaAABn2wptlQE123.png "title=" 1.png " alt= "Wkiom1c-frfwlewaaabn2wptlqe123.png"/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/80/5B/wKiom1c-fpvTt6FGAAA3XAOelpU141.png "title=" 2.png " alt= "Wkiom1c-fpvtt6fgaaa3xaoelpu141.png"/>

(2) Find by regular expression

Operation Options:!

Operation Example:! Therefore, the meaning of the name, is to deny a search condition, and logical-not is not similar,

Find./! ' *.c '-print find file names that are not. C and print them out

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/5B/wKiom1c-hZ7TILrgAADYHxhl4TA177.png "title=" 31.png "alt=" Wkiom1c-hz7tilrgaadyhxhl4ta177.png "/>


Other regular expressions include the following:

-A with conditions

-O or condition

-not Non-conditional (the function of this parameter is similar to the negative parameter '! ')

2. Search 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.


Operation Options:-size-n

Examples of operations: Find~-size-100k finding files less than 100k

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/59/wKioL1c-iQnxOfThAAD1FxmB8wM193.png "title=" 4.png " alt= "Wkiol1c-iqnxofthaad1fxmb8wm193.png"/>


Operation Options:-size +n

Examples of operations: Find~-size +100k finding files less than 100k

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/80/5C/wKiom1c-iMGwZSySAAA03IfZmbM838.png "title=" 5.png " alt= "Wkiom1c-imgwzsysaaa03ifzmbm838.png"/>


Operation Options:-size N

Examples of operations: Find~-size 100k finding files for 100k

There is no file equal to 100k under my system.


3. Search by file depth

Operation Options: MaxDepth

Operation Example: Find-maxdepth 2-name tmp find file tmp in a directory with a depth of 2

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/5C/wKiom1c-i1GDL9zhAAA7sP8mmRQ142.png "title=" 6.png " alt= "Wkiom1c-i1gdl9zhaaa7sp8mmrq142.png"/>


Operation Options: Mindepth

Operation Example: Find-mindepth 1-maxdepth 3-name tmp find file tmp in depth of 1 to 3

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/5C/wKiom1c-jH_Dfa-LAACpBsxuHpI928.png "title=" 7.png " alt= "Wkiom1c-jh_dfa-laacpbsxuhpi928.png"/>


4. Search by file permissions

Operation Options:

-perm Search by file permissions

-user (or-uid n n is the ID of the user account) is searched by the file owner

-group (or-gid n n is the ID of the group name) is found by the group that owns the file

Operation Example: Find-type f-perm 777

Find-type F-user 777

Find-type F-group 777 (This is not the case, look at the above so much presumably everyone will be)


5. Find by file type

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

Operation Options:-type

Operation Example:find. -type P,find =type f , et cetera.


6. Search by file time

Three timestamps in the Linux file system:

▲ Access Time (-atime): The last time the user visited the 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.


Operation options:-atime,-mtime,-ctime (with +,-to indicate greater than and less than)

Examples of operations:Find/-atime-1, find/-atime + 1, find/-mtime-2, find/-ctime , etc.

Special: Find/-newer tmp----> Find newer files than test.c


7.find is used in conjunction with Xargs

Xargs parameter converts standard input to command-line arguments

Operation options:-atime,-mtime,-ctime (with +,-to indicate greater than and less than)

Operation Example:find-type f-name "*.txt"-print0 |xargs-0 rm-f(delete the found file, xargs-0 will be the input delimiter);

find-type f-name "*.c"-print0 |xargs-0-1 (count the number of lines for all C program files)



This article is from "drip" blog, please be sure to keep this source http://10740329.blog.51cto.com/10730329/1775362

Summary of the usage of the Find command under Linux Linux

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.