Use the find command in linux (search for files in linux)

Source: Internet
Author: User
This article describes how to use the find command in linux (linux file search). For more information, see LinuxFind.

Find the file MyCProgram. c in the current directory and subdirectory
# Find.-name "MyCProgram. c"

Search for files and ignore case sensitivity
# Find.-iname "MyCProgram. c"

Search for files that do not contain MyCProgram. c
Find.-maxdepth 1-not-iname "MyCProgram. c"

Search for passwd in subdirectories 3 to 5 under/
# Find/-mindepth 3-maxdepth 5-name passwd

Search and execute commands
Find.-iname "MyCProgram. c"-exec md5sum {}\;

Search for files larger than MB
# Find ~ -Size + 100 M

Search for files smaller than MB
# Find ~ -Size-100 M

Search for files equal to MB
# Find ~ -Size 100 M

Search for the maximum five files in directories and subdirectories
Find.-type f-exec ls-s {}\; | sort-n-r | head-5

Find the minimum five files in directories and subdirectories
# Find.-type f-exec ls-s {}\; | sort-n | head-5

Search for non-zero and minimum size of five files
# Find.-not-empty-type f-exec ls-s {}\; | sort-n | head-5

Search for files with write permissions for all users
# Find.-perm-g = w-type f-exec ls-l {}\;

In the/logs Directory, find and delete files whose changes were earlier than 5 days.
$ Find logs-type f-mtime + 5-exec rm {}\;

Find common files in the/var/logs directory that were modified seven days ago and ask them before deletion.
$ Find/var/logs-type f-mtime + 7-OK rm {}\;

You can use a certain file name pattern to match the file. remember to use quotation marks to cause the file name pattern. otherwise, matching and expanding will cause confusion of the find parameter.
$ Find.-name [A-Z] *-print

In the current directory, find the file with a permission of 755, that is, the file owner can read, write, and execute. other users can read and execute the file.
$ Find.-perm 755-print

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.