Find Tips-One of the "Linux Command Five" series

Source: Internet
Author: User

One command a day, a record,

I want to be a big God, hahaha.

This original article belongs to the "Linux Greenhouse" blog.

The blog address is http://roclinux.cn.

Article author for Roc

I hope you can donate to support the operation and development of the Linux greenhouse blog. See "About Donations"

==

First look at the example, to find a general understanding of the final summary (if you just want to review, you can go straight to the end to see the summary)

1. Want to check the current folder and subfolders There are no files named "abc" (not the directory)

# Find. -name ABC

. : Represents the current directory

-name: Indicates that you want to find by name

2. To see if there is a "xyz" directory in the current folder and sub-folder

# Find. -type d-name xyz (no before D-)

-type: Indicates the set type, D indicates the folder type, can be replaced with F (normal file), L (linked file)

3. Want to find out all the suffixes in the current folder and sub-folders are ". txt" files

# Find. -name "*.txt"

Similar to 1, but the-name parameter is a pattern, not a specific file name

4. Want to find out what the "ROC" user 's own files are in the current directory and its subfolders

# Find. -user Roc

-user: Used to set the name of the owning user, here can be replaced by-group, that is, the name of the owning user group

5. You want to find all the files in the current folder and sub-folders with permission set to 755

# Find. -perm 755

-perm: Used to set permissions

6. To find files with both B and 3 characters in the current folder and subfolders: Using Regular expression technology

# Find. -regex '. *b.*3′

-regex: Indicates that a regular expression is used to match. Note that This command matches the "full path", which means that it is preceded by an "./" symbol in the output result.

7. If you want to output the contents of the "*.abc" file found with the Find command

# Find. -type f-name "*.abc"-exec cat {} \;

-exec indicates that a match found by find will be used as the parameter for "command set after-exec"

You can use-OK instead of-exec, which will require the user to confirm (Y is yes, n is no) to operate on each match

Command last {} \; Don't forget to write, where {} represents each find item in the results found with find.

8. Find files accessed in the current directory within 5 minutes

# Find. -amin-5

Accessed with Amin, modified with mmin, file status changed over Cmin

Accurate to the minute with amin,mmin,cmin, accurate to the day's use Atime,mtime,ctime

Within 5 minutes of use-5, in 5 minutes or more with +5

9. Want to find all files with file size greater than 10M in current directory and sub-directory

# Find. -size +10000000c

-size: Represents the file size, + means greater than a certain number,-represents less than a certain number. C means the unit is byte, you can change C to k,m,g.

10. All of the find commands above are to find the current directory and its subdirectories. If you do not want to go deep into a subdirectory, but instead find only the current level of the directory, you can:

# Find. -maxdepth 1 -name "*.C"

Summarize:

By the above example, we have already identified find. Ascend a level.

1 command format for find

Find pathname-options filename [-print,-exec,-ok [command {} \;]]

2 command functions

Find files used in the file tree

3 Command parameters:

The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, and/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
The-exec:find command executes the shell command given by the parameter to the matching file. The command {} \;, note the space between {} and \;
-ok: The same as-exec, except that the shell command given by the parameter is executed in a more secure mode, prompting the user to determine whether to execute before executing each command.

4 option Options

Based on file name

-name: Support "*" match, need to use regular-regex

Depending on file size

-size:-size n[c,k,m,g], Note that K is lowercase and uppercase is wrong. You can specify a range, such as-size-10m-size + 5M, that represents 5m<n<10m by file name

Depending on file type

-type: followed by D (directory), f (normal file), p (pipeline file), B (Block device), l (link file), s (socket file)

Depending on time:

Visit:-amin,-atime

Modified:-mmin,-mtime

Status change:-cmin,-ctime

According to the identity of the owner;

Owner:-user,-nouser

Owning group:-group,-nogroup

Based on permissions:

-perm

Other:

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

-newer file1! File2 look for a file that changes time than the file File1 new but older than the file file2.

-fstype: Find files located in a file system of a certain type, these file system types can usually be found in the configuration file/etc/fstab, which contains information about the file system in this system.

-mount: Does not cross the file system mount point when locating files.

-follow: If the find command encounters a symbolic link file, it tracks to the file that the link points to.

-cpio: Use the cpio command for matching files to back up these files to the tape device.

Each option can be used together

Find Tips-One of the "Linux Command Five" series

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.