1-12 use of the Rhel7-find command

Source: Internet
Author: User

1. Find Files
The Find command is a directory structure that searches for files and performs specific actions
The Find command provides a fairly large number of search criteria and is powerful

2. Format
Usage:find Pathname-options[-print]

Find [-h] [-l] [-p] [-D debugopts] [-olevel] [path ...] [Expression]

3. Parameters
-print output (sometimes dispensable, sometimes must have, sometimes must be none)
Pahtname: Path #在指定路径中搜索

4. Options
-option: (option)

-name "" #根据文件名称进行查找
-perm #根据文件权限进行查找
-prune #忽略, if it is a directory, do not enter the lookup
-depth #在指定目录中查找后, enter its subdirectory to find,
Ignore prune when #当有 the-depth option
-user #根据文件属主查找
-nouser #查找没有属主的文件 (without this user in/etc/passwd), no user name required
-group #根据文件属组查找
-nogroup #查找没有属组的文件, with Nouser
-mtime-n +n atime ctime mtime #根据文件修改时间查找,
#-n n days, +n n days ago (not future time OH)
-type [B,d,c,p,l,f] #根据文件类型查找
B-block devices, D-Directories, C-character devices, p-pipes, L-connections, F-common
-size #根据文件长度进行查找
-fstype #在某个文件系统中查找文件
-mount #不再其他的文件系统中查找, not across mount points
-follow #如果找到的是连接文件, you will follow the source file
-cpio #将查找到的结果, backup wood has this option AH?!


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


Echo $HOME #查看home变量的值, which determines the path represented by ~

Experiment:
1. Search by file name
The file name option is the most common option for the Find command.
Either use this option alone, or use it with other options.

Attention
You can use a file name pattern to match files,
Remember to enclose the file name pattern in quotation marks.

Regardless of the current path, if you want to find files in your own root directory that match the *.txt file name, $home
Using ~ as the ' pathname ' parameter, the tilde ~ represents your $home directory.

To find files with the file name beginning with host in the/etc directory, you can use:

Find " host* "  Find"host*" -Print

Find " *.txt  "-print #必须带" "

2. Search by permissions
Follow the file permission mode with the-perm option,

To find files by file permission mode. It is best to use the octal permission notation.

Example:
If you look for a file with a file permission bit of 755 in the current directory,
The owner can read, write, execute, other users can read, execute files,
Can be used:
[[email protected] ~]# Find ~-perm 777

3. Ignore
Use the-prune option to indicate which directories need to be ignored.

Be careful when using the-prune option, because if you use the-depth option at the same time, the-prune option is ignored by the Find command.
[[Email protected] ~] #find test-path "test/dir0"-prune-o-print
Ignore files in directory Test/dir0

-path-prune usage: see : Use of options-path and-prune in the Find command

4.depth
You want to match all of the current files before looking in subdirectories.
In the following example, the Find command starts at the root of the file system and looks for a file named Con.file.

It will first match all the files and then go to the subdirectory to find them.
[[Email protected] ~] #find test-depth-path "test/dir0/*"-print
Note:-depth to be in front of the path or alert

5.user Nouser
[[Email protected] ~] #find/opt-user Xiaogan

[[Email protected] ~] #find/opt-nouser

6. Group
Same 5


7.mtime
If you want to find the file by changing the time, you can
Use the Mtime,atime or CTime option.
If the system suddenly does not have free space, it is possible that the length of a file grows rapidly during this period, you can use the Mtime option to find such a file.

Use a minus sign-to limit the time to change files that are less than n days away,
Use the Plus + to limit the files that change time before the current n days.

In the System/root directory, you want to find files that change within 5th,

Find/root-mtime-5-print

[[Email protected] ~] #find. -mtime-3 #查找3天内修改过的文件

[[Email protected] ~] #find. -mtime +3 #查找3天前修改过的文件

8.type!

-type find a file of a certain type,
B-block device files.
D-Directory.
C-character device file.
P-Pipeline file.
L-Symbol link file.
F-Normal file.
! Take counter
To find all the directories in/etc directory, you can use:
Find/etc-type D-print

Find all types of files except directories in the current directory,
[[email protected] ~]# find. ! -type D

Find all the symbolic link files in the/etc directory
Find/etc-type L-print
[[Email protected] ~] #find/dev-type B #查找 The block device file in the/dev directory

[[Email protected] ~] #find/dev! -type b #查找 A non-block device file in the/dev directory

[[email protected] ~]# Find/-type P


9.size

-a-o-a and-o or-not! Non -
You can find files by file length;
The length of the file referred to here can be measured in blocks (block),
can also be measured in bytes.
The length of the measured file in bytes is expressed in the form of n C;
The length of a block measurement file is only represented by a number.

When looking up files by file length, this is generally the size of the file in bytes, and it is easier to convert by using blocks to measure the file system.

In the current directory, look for files with a file length greater than 1 m bytes:


Find. -size +1000000c-print

Look for files with a file length of exactly 100 bytes in the/home/apache directory:
Find/home/apache-size 100c-print

Look for files that are longer than 10 blocks in the current directory (a block equals 512 bytes):

Find. -size +10-print


find/etc/-size +20k-a-size-50k
-A and and-O or OR
+ Over-below
[[Email protected] ~] #find. -size +20k-a-size-30k file between the #查找当前目录下大小在20k ~30k

1-12 use of the Rhel7-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.