Linux-find "Recursive search file name"

Source: Internet
Author: User
Tags file permissions

1 command format:
<指定目录><指定条件><指定动作>

Most common example: Find file names (ignoring case)

$find . -iname sqlquery.java

1.1 < designated directory;:

The directory to search for and all its subdirectories. The current directory is assumed by default. find default recursive specified directory. There can be multiple directories, separated by spaces between directories.

[[email protected]]$find /etc /tmp /root -name passwd

1.2 < specified conditions;:

The characteristics of the file to be searched.

[1] Search by file name
-name Search by file name
-iname Search by file name, but not case-sensitive
-prune not found in the currently specified directory
-depth When looking for a file, first find the file in the current directory, and then look in its subdirectories
[2] Finding files based on the users and groups they belong to
-user Find files according to the owner of the file

$find//查找在系统中属于FRED这个用户的文件
-groupFind a file by the group to which it belongs

$find//查找在系统中属于group组名cat的文件 
[3] based on UID and GID to find users
-uid

#find  500       //查找uid是500 的文件
-gid

#find  1000      // 查找gid是1000的文件
[Use of 4]-a,-o,-not
-AConnect two different conditions (two conditions must be met at the same time)

#find /tmp -name "*.sh" -a -user root
- oConnect two different conditions (two conditions to satisfy one)
#find"*.sh" -o -user root
-notThe reverse of the condition
#find /tmp -not -user root
[5] file timestamp based on the relevant properties to find files
-atimeLast Access Time unit: Day
-mtimeLast Content Modification time unit: Days
-ctimeLast Property modification time unit: Days
-aminLast access time unit: minutes
-mminLast Content Modification time unit: minutes
-cminLast Property modification time unit: minutes
-newer file1! file2Look for changed times than files File1 new but older files than files File2
    1. # Find/tmp-atime +5 //For finding files that have not been accessed within five days
    2. # Find/tmp-atime-5 //indicates finding files accessed within five days
[6] Finding files based on file type
-typeFind a file of a certain type
File type: the
F Common Files
Catalog D
L Symbolic Link file
C-Character device files
P Pipeline File
B-Block device files
s socket file
#find /tmp -type s
[7] Search for files based on size
-size N[c]Find files with a file length of n blocks, with C indicating the length of the file in bytes
    1. # Find/tmp-size 2M //Find files equal to 2M in/tmp directory
    2. # Find/tmp-size +2m //Find files larger than 2M in the/tmp directory
    3. # Find/tmp-size-2m //Look for files less than 2M in the/tmp directory

$find . -size +1000000c        //在当前目录下查找文件长度大于1 M字节的文件
$find / -empty        //查找在系统中为空的文件或者文件夹 

[8] Finding files based on file permissions

-perm
    1. # Find/tmp-perm 755 //Find files in the/tmp directory with permissions of 755
    2. #Find /tmp-perm +222 //indicates that only one type of user (owner, group, other) can match write permissions
    3. #Find /tmp-perm-222 //indicates that all category users must be satisfied with Write permission
[10]-nouser and-nogroup
-nogroupFind a file that does not have a valid owning group, that is, the group to which the file belongs does not exist
-nouserFind files with no valid owner

#find / -nogroup -a -nouser    //在整个系统中查找既没有属主又没有属组的文件(这样的文件通常是很危险的,作为系统工程师的我们应该及时清除掉)

$find / -nouser        //查找在系统中属于作废用户的文件 

1.3 < designated action;:

Specific processing of the search results.

-print //actions by default
-ls //Find and then use LS to display it
-ok [commend] //Find out when executing a command to ask the user whether to perform
-exec [commend] //Search after the execution of the command without asking the user, directly execute

Note that the-ok and-exec commands take subsequent arguments on the command line as part of their arguments until they are terminated by the \ sequence. The Magic String {} is a special type of parameter for the-OK and-exec commands, which will be replaced by the full path of the current file.

#find /tmp -atime +30//删除查找到的超过30天没有访问过文件
Here is the use of {}: replace the found file
#find"*.old"700

2 Examples of commands

Search the file name under the/etc directory that contains Del.

$find /etc -name‘*del*‘

The "config.py" file information is immediately displayed on the screen after the system finds the "config.py" file.

$find"config.py" -ls
Searches the current directory for all the normal files that have been updated in the last 10 minutes. If you do not add the-type f parameter, search for normal files + special files + directories.
$ find . -type-10
JPG change rar

Linux-find "Recursive search file name"

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.