Linux-find "Recursive search file name" __linux

Source: Internet
Author: User
Tags file permissions
1 command format:
$ find < Specify directory > < specify conditions > < specify action >

Most common example: Find file name (Ignore case)

$find. -iname Sqlquery.java

1.1 < Designated directory:

The directory to search for and all of its subdirectories. The current directory is assumed by default. Find default recursion specifies the directory. There can be multiple directories, separated by spaces.

[admin@r42h06016.xy2.xxx.com] $find/etc/tmp/root-name passwd

1.2 < specified conditions:

The characteristics of the file to search for.

[1] Search by filename
-name to find by file name
-iname lookup based on filename, but not case-sensitive
-prune is 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] Find files based on the users and groups to which they belong
-user to find files by file owner

$find/-user Fred 		//Find files belonging to Fred This user in the system
-group to find files according to the group to which the file belongs

$find/-group Cat 		
[3] search for users based on UID and GID
-uid

#find  /tmp-uid       //Find a file with UID 500
-gid

#find  /tmp-gid 1000      //Find GID is 1000 files
[Use of 4]-a,-o,-not
-A connects two different conditions (two conditions must be met simultaneously)

#find/tmp-name "*.sh"-a-user root
-O connects two different conditions (two conditions satisfy one)
#find/tmp-name "*.sh"-o-user root
-not to the condition of the reverse
#find/tmp-not-user Root
[5] Find files based on file timestamp related properties
-atime Last visit time unit: Days
-mtime Last Content modification time unit: Days
-ctime Last Property modification time unit: Days
-amin Last visit time unit: minutes
-mmin Last Content Modification time unit: minutes
-cmin Last Property modification time unit: minutes
-newer file1! File2 find change time than file File1 new but older file File2 file
#find/tmp-atime +5  //means to find files that have not been accessed within five days
#find/tmp-atime-5   //To find files accessed within five days
[6] Find files based on file type
-type find a file of a certain type
File type:
F Normal File
D Directory
L Symbolic Link file
C Character device file
P Pipeline File
B Block Device file
s socket file
#find/tmp-type S
[7] Find 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
#find/tmp-size  2M           //Find files equal to 2M in/tmp
#find/tmp-size +2m           //Find files that are greater than 2M in/tmp directory
#find/tmp-size -2M           //Find files less than 2M in/tmp directory

$find. -size +1000000c        //Find files with a file length greater than 1 m bytes in the current directory
$find/-empty 		       

[8] Find files based on file permissions -perm

#find/tmp-perm 755           //Find files in/tmp with permissions of 755
#find/tmp-perm +222          //indicates that only one type of user (owner, group, other) has a matching write permission on the line
#find /tmp-perm-222          //indicates that all categories of users must be satisfied with write access
[10]-nouser and-nogroup
-nogroup find a file that does not have a valid owning group, that is, the group that the file belongs to does not exist
-nouser find files without a valid owner

#find/-nogroup-a-nouser    //Find files in the entire system that have neither the owner nor the group (such files are usually very dangerous, and as a system engineer we should clear them in time)

$find/-nouser 	       

1.3 < Designated action:

Perform specific processing of the search results.

-print//action by default
-ls//Find to display with LS
-OK [commend]//Find out when executing the command to ask the user if they want to perform
-exec [commend]//Search after executing the command without asking the user, execute directly

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

#find/tmp-atime +30–exec rm–rf {} \//delete files that have not been accessed for more than 30 days
Here to note the use of {}: replace the found file
#find/tmp-name "*.old" | Xargs chmod 700

2 Command Examples

Search the/etc directory for file names that contain del files.

$find/etc-name ' *del* '

When the system finds the "config.py" file, it immediately displays the "config.py" file information on the screen.

$find. -name "config.py"-ls
Searches the current directory for all 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 f-mmin-10


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.