Linux find command details, Linuxfind command details

Source: Internet
Author: User

Linux find command details, Linuxfind command details
Find command in Linux

The find command is used to find files in a specified directory. Any string located before the parameter is considered as the directory name to be searched.

If you use this command without setting any parameters, the find command searches for subdirectories and files in the current directory. All the subdirectories and files found are displayed.

Find syntax
Find (option) (parameter)
Common option Parameters

-Name <template style>: Specifies the string as the template style for searching for files or directories.

-Regex <template style>: Specifies the string as the template style for searching for files or directories.

-Size <file size>: searches for objects of the specified file size.

-Typ <file type>: searches for files that match the specified file type.

-Path <template style>: Specifies the string as the template style for searching for directories.

-Perm <permission value>: searches for files or directories that match the specified permission value.

-Help or -- help: Online help

-False: Set the return value of the find command to False.

-True: Set the return value of the find command to True.

-Amin <minute>: searches for files or directories that have been accessed at a specified time, measured in minutes.

-Cmin <min>: searches for files or directories that have been changed at the specified time.

Atime <24 hours>: searches for files or directories that have been accessed at a specified time. The unit is 24 hours.

Ctime <24 hours>: searches for the files or directories changed at the specified time. The unit is 24 hours.

-Gid <group ID>: searches for files or directories that match the specified group ID.

-Group <group Name>: searches for files or directories that match the specified group name.

Uid <user ID>: searches for files or directories that match the specified user ID.

User <owner name>: file or directory of the lookup operator and specified owner name

Some other parameters are ignored for listing:

For details, refer to the "find" command for Linux commands.

Instance

Matching by file or regular expression

List all files and folders in the current directory and subdirectory
find .
Find the file name ending with .txt in the/homedirectory
find /home -name "*.txt"

Same as above. Case Insensitive. Use iname.

find /home -iname "*.txt"
Check all files ending with .txt and. cfg in the current directory and sub-directory.
find . -name "*.txt" -o -name "*cfg"
Match the file path or file
find /usr/ -path "*local*"
Matching file Paths Based on Regular Expressions
find . -regex ".*\(\.txt\|\.pdf\)$"
Case-insensitive Regular Expression matching
find . -iregex ".*\(\.txt\|\.pdf\)$"

Negative Parameter

find /home ! -name "*.txt"

Search by file type

Find.-type parameters

Type parameter list:

F: Common File

L: symbolic connection

D: Directory

C: character device

B: Block devices

S: Socket

P: Fifo

Eg:

find . -type ffind . -type d

Search by file Timestamp

Find.-type f Timestamp

In a Linux file system, each file has three timestamps.

Access time (-atime/day,-amin/minute): The last access time of the user.

Modification time (-mtime/day,-mmin/minute): The last modification time of the file.

Change Time (-ctime/day,-cmin/minute): The last modification time of the file data element (such as permission.

Search for all files that have been accessed in the last seven days

find . -type -atime -7

Search for all files that were accessed 7 days ago

find . -type -atime 7

Search for all files that have been accessed for more than seven days

find . -type -atime +7

Search for all objects that have been accessed for more than 10 minutes

find . -type f -amin +10

Match by file size

Find.-type f-size file size unit

B: block (512 bytes)

C: byte

W: Word (2 bytes)

K: kilobytes

M: MB

G: G bytes

Search for files larger than 10 KB

find . -type f -size +10k

Search for files smaller than 10 KB

find . -type f -size -10k

Search for files equal to 10 KB

find . -type f -szie 10k

Delete matching files

find . -type f -name "*.txt" -delete

Matching Based on File Permissions

Search for files with permissions of 777 in the current directory

find . -type f -perm 777

Find the txt file whose permission is not 700 in the current directory.

find . -type f -name "*.txt" ! -perm 700

Find all the files owned by the current directory user zhang

find . -type f -user zhang

Find all the files owned by gzhang in the current directory user group

find . -type f -group gzhang

Search for files with a length of 0

find . -type f -empty

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.