Find details of the Linux command

Source: Internet
Author: User
Tags dmesg

Introduction
One of the most commonly used Linux basic commands in find work is to find the files or directories we want by using parameters such as type, size, name, modification time, access time, change time, permissions, and so on. Find lookup can also be combined with a number of commands to achieve the results we want, such as: with SED, xargs and other commands used, through the pipe symbol "|" Can.
When we learn and use Linux commands and configuration files, we learn to use man to help with learning, and man can not only view the command's help documentation, but also see the help documentation for the configuration file.
Find-search for files in a directory hierarchy
Search for files in the directory hierarchy
Grammar
Find [-h] [-l] [-p] [-D debugopts] [-olevel] [path ...] [Expression]
How to find
1. Depth of search (-maxdepth)
This parameter must follow the path, before the other parameters, otherwise it will be an error

find /var/log/ -maxdepth 1 -type f            /var/log/anaconda.ifcfg.log/var/log/dmesg/var/log/dmesg.old

2. Search by Type (-type)
find /data -type f
F: Normal file D: Directory L: Symbolic link s:socket B: Chunk file
3. Search by file name (-name)
find /data -type f –name “*.log”
4. Search by modified time (-mtime)
find / -type f –name “*.log” –mtime +4 表示查找四天前的
TIME schematic diagram:

In the time attribute, in addition to the modification time mtime, but also according to the access time Atime and the property change time CTime to find, but not very common.
5. Search by authority (-PERM)

[[email protected] tmp]# find /tmp/ -type f -perm 644 /tmp/rsyncd.conf/tmp/nn/tmp/kk[[email protected] tmp]# ls -ltotal 4-rw-r--r-- 1 root root   0 May 18 21:01 kk-rw-r--r-- 1 root root   0 May 18 21:02 nn-rw-r--r-- 1 root root 466 May 17 05:32 rsyncd.conf[[email protected] tmp]# ls -l kk|awk ‘{print $1}‘|tr "\-rwx" "0421" –有特殊意义,所以需要转义0420400400

6. Search by User (-user)
find / -user root
7. Search by Size (-size)

find / -type f –size +100M 查找大于100M的文件-100M 小于100M100M 等于100M+100M 大于100M    其它的依此类推

8. Search by Inode number (-inum)
find / -type f –inum xxxx
9,! : Take counter
find . -maxdepth 1 -type d ! -name "."
10,-A: And and

find /tmp/ -type f -name "k*" -a -name "*k"/tmp/kk

11,-O: OR OR

find /tmp/ -type f -name "k*" -o -name "*n" /tmp/nn/tmp/kk

Use case
1, find. -perm |xargs chmod 777
Find all files with permissions of 700 under the current directory (and subdirectories) and reset their permissions to 777.
2, find. -type F |xargs ls-l
Find the file and view its details.
3, find. -maxdepth 1-type D! -name "."
Find all directories in the current directory, exclude "." Current directory with a lookup depth of 1
4, find oldboy/-type f-name "*.sh" |xargs sed-i ' s#ricky#ricky#g '

5. Find and delete
Find/data-type f-name "*.txt" |xargs rm–f
or Find/data-type f-name "test"-exec rm {} \;
{}:find found content
; Command end "\ Backslash is used to escape"

Find details of the Linux command

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.