[Reprint] Linux Find command

Source: Internet
Author: User

Reprinted from Http://www.jb51.net/os/RedHat/1307.html

The Linux Find command searches the directory structure for files and performs the specified actions .

The Linux Find command provides quite a lot of search criteria and is powerful. Because find has powerful features, it has a lot of options, most of which are worth taking the time to look at.

Even if the system contains a network file system (NFS), the Find command works equally well in the file system, and you only have the appropriate permissions.

When running a very resource-intensive find command, many people tend to put it in the background because it can take a long time to traverse a large file system (this refers to a file system with more than 30G bytes).

1. Command format:

· Find Pathname-option [-print] [-exec-ok command] {} \;

2. Command function:

Used to locate files in the file tree and to make corresponding processing

3. Command parameters:

The directory path that the Pathname:find command looks for. For example . Represents the current directory / represents 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 corresponding command is in the form of ' 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. Command options:

-name finds files by file name .
-perm to find files according to file permissions .
-prune Use this option to have the Find command not be found in the currently specified directory (that is, ignoring the specified directory) , and if the-depth option is used at the same time,-prune will be ignored by the Find command.
-user username search for files according to the owner of the file .
-group GroupName finds files according to the group to which the files belong .
-mtime-n +n to find files according to the file change time ,-n refers to n days or less, +n refers to n days ago Modify

-atime-n +n check access by file access time

-Ctime-n +n by file creation time to find files,-n refers to n days, +n refers to n days before the create

-nogroup     Find does not have a valid owning group file, that is, the group to which the file belongs does not exist in/etc/groups.
-nouser       Find no valid primary file, that is, the owner of the file does not exist in the/etc/passwd.
-newer file1! file2   Find change time file1 the new but file2 older files than files.
-type finds a file of a certain type, such as:
B-block device file.
D-Directory. The
C-character device file.
P-pipe file. The
L-Symbolic link file.
F-Normal file.
-size N[c]     finds files with file lengths of n blocks, with C , indicating file lengths in bytes .

-depth When looking for a file, first find the file in the current directory and then look it up in its subdirectories (so that the lookup finds the directory before entering the subdirectory )
-fstype Find files located in a file system of a certain type , file system Type Table configuration file--- /etc/fstab
-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 on the matching files to back up these files to the tape device.

In addition, the following three differences:

-amin N Find the last n minutes of files accessed in the system
-atime N Find The last n*24 hour access file in the system


-cmin n Find files in the last n minutes of the system changed file status
-ctime n Find files that have changed file status in the last n*24 hours of the system


-mmin n Find files that have changed file data in the last N minutes of the system
-mtime n Find files that have changed file data for the last n*24 hours (n days) in the system

5. Usage examples:

1) Find files that have been modified within 48 hours

Find-atime-2

2) Find files with the file name ending with. Log in the current directory

Find . -name "*.log" # #. The number represents the search in the current directory

3) Find all files with permission 777 under the/opt/soft/test/directory

find/opt/soft/test/-perm 777

4) Find common files that end with. Log in the directory

Find. -type f-name "*.log"

5) Find and sort all current directories

Find. -type D | Sort

6) Find files with current directory larger than 1K

Find. -size +1000c-print

============================================

Query command

Describe

Find ~-name "*.txt"-print

Check. txt files in home and show

Find. -name "*.txt"-print

Find. -name "[a-z]*"-print

Check for files that begin with a capital letter

Find/etc-name "host*"-print

Check for files that begin with host

Find. -name "[A-z][a-z][0–9][0–9].txt"-print

Find txt files with two lowercase letters and two numbers

Find. -perm 755-print

Find all files and directories in the current directory with file mode 777

Find. -perm-007-exec ls-l {} \;

Find. -type D-print

Print directory Structure

Find. ! -type D-print

Print non-catalog files

Find. -type L-print

Print a symbolic link file

Find. -size +1000000c-print

Find. -size +1000k-exec ls-ld {};

Files with file lengths greater than 1M are checked

Find. -size 100c-print

Files with file lengths equal to 100c

Find/home-size +512k

Check for files larger than 512k

find/home-size-512k

Check for files smaller than 512k

Find. -size +10-print

Files with file lengths greater than 10 blocks

No unit, thumb block (1 block = 512 bytes)

Cell C, Bytes byte

Unit k, refers to kilobytes (KB)

Find/etc-name "passwd"-exec grep "Cnscn" {} \;

See if there are CNSCN users

Find. -name "yao*" | Xargs file

Find. -name "yao*" | Xargs echo "" >/tmp/core.log

Find. -name "yao*" | Xargs chmod o-w

Find-name april*

Find files starting with April in the current directory

Find-name april* fprint File

Finds files starting with April in the current directory and outputs the results to file

Find-name ap*-o-name may*

Find files that start with an AP or May

Find/mnt-name Tom.txt-ftype VFAT

Find files with name Tom.txt and file system type VFAT under/MNT

Find/mnt-name T.txt! -ftype VFAT

Find files with name Tom.txt and file system type not VFAT under/mnt

Find/tmp-name wa*-type L

In/tmp, look for a file with a type of symbolic link that begins with the name WA

-mtime-n +n (-n refers to the nth day or less, +n refers to n days ago) eg:-mtime-6 +3 last 6 days 3 days ago

-atime

-ctime

Find/home-mtime +2

Under/home, check the files that were changed two days ago.

Find/home-mtime-2

Under/home, check the files that have been changed in the last two days

Find/home-mmin +60

Under/home, check the files that were changed 60 minutes ago.

Find/home-mmin-5

Under/home, find files that have been modified in the last 5 minutes

Find/home-atime-1

Under/home, check for files that have been accessed within 1 days

Find/home-atime-2

Under/home, find files accessed within 2 days (within the last 48 hours)

Find/home-used-2

Files or directories that have been accessed within 2nd

Find/home-amin +30

Under/home, check the files that were accessed 30 minutes ago

Find/home-amin-10

Under/home, find files accessed in the last 10 minutes

Find/home-newer Tmp.txt

Check the update time at/home than tmp.txt new file or directory

Find/home-anewer Tmp.txt

Check access time in/home to a newer file or directory than tmp.txt

Find/home-user CNSCN

List files or directories belonging to user CNSCN in the/home directory

Find/home-uid +501

Lists files or directories in the/home directory for users with identifiers greater than 501

Find/home-group CNSCN

List files or directories in/home with group CNSCN

Find/home-gid 501

List files or directories with group ID 501 in/home

Find/home-nouser

Lists files or directories in/home that are not local users

Find/home-nogroup

List files or directories in/home that do not belong to a local group

Find/home-name tmp.txt-maxdepth 4

List Tmp.txt in/home with a depth of up to 3 layers

Find/home-name tmp.txt-mindepth 3

Start with the 2nd floor.

Find/home-empty

Find a file size of 0 or an empty directory

Find/home-links +2

Files or directories with a hard connection number greater than 2

[Reprint] Linux Find command

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.