One of the common Linux commands: find

Source: Internet
Author: User

one of the common Linux commands:Find

Find,find is a traversal lookup of the entire system without specifying a lookup directory

Use format: Find [specify Find directory] [find rule] [action executed after find]

[Specify find directory] for example:

[Email protected] ~]# find/etc-name "passwd"

/etc/passwd

/etc/pam.d/passwd

[ find rules ]

( 1 ) Search by file name

#-name       // Search by file name (exact lookup)

#-iname// Search by file name, but not case sensitive

Here is another introduction to the name of the knowledge of the wildcard

* represents wildcard arbitrary characters

[Email protected] ~]# find/etc-type f-name "passwd*"

/etc/passwd

/etc/passwd-

/etc/pam.d/passwd      

? Indicates The wildcard of any single character

[Email protected] ~]# find/etc-type f-name "passwd?"

/etc/passwd-

(2) to find files based on the users and groups that the files belong to

#-user// search for files based on owner

#-group// search for files by genus Group

[[email protected] HEJP] #find/home/-user HEJP

/home/ddd

/home/ddd/.bash_logout

/home/ddd/.bashrc

/home/ddd/.bash_profile

/home/hejp

/home/hejp/.bash_logout

/home/hejp/.bashrc

/home/hejp/.bash_profile

(3), based on uid and GID to find users

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

#find/tmp-gid 1000// find the GID is a 1000 file

(4),-a and-o and–not use

# -A connection two different conditions (two conditions must be met at the same time)

[Email protected] ~]# find/server/scripts/-name "*.sh"-a-user root

/server/scripts/ipv_server.sh   

#-O Connection two different conditions (two conditions to satisfy one)

[Email protected] ~]# find/server/scripts/-name "*.sh"-o-user root

/server/scripts/ipv_server.sh   

#-not on conditional inversion

[[email protected] HEJP] #find/home/-name "*.test"-not-user HEJP

/home/hejp/hello.test

(5) to find files based on the relevant properties of the file timestamp

we can use the stat command to view the time information for a file as follows:

[[Email protected]]# stat/etc/passwd

File: '/etc/passwd '

size:1467 blocks:8 IO block:4096 Regular file

device:803h/2051d inode:146713 links:1

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root)

access:2016-03-1310:36:08.809835981 +0800

modify:2016-03-0321:59:49.717548713 +0800

change:2016-03-0321:59:49.719585578 +0800

#-atime

#-mtime

#-ctime

#-amin

#-mmin

#-cmin

So here atime,mtime,ctime is the corresponding "Last access time" Last content modification Time "Last Property modification Time", here the atime unit refers to "day ", the unit of Amin is the minute

#find/tmp–atime +5// To find files that have not been accessed within five days

#find/tmp-atime-5// find files that have been accessed within five days      

(6), find files according to file type

-type

F// normal file

d// directory file

L// link file

b// block device files

c// character device files

P// pipeline file

s//socket file

[[email protected] HEJP] #find/home/hejp/-type F

/home/hejp/hello.test

/home/hejp/.bash_logout

/home/hejp/.bashrc

/home/hejp/.bash_profile

(7), find files based on size

-size

#find/tmp-size 2M// find files equal to 2M in/tmp directory

#find/tmp-size +2m// find files larger than 2M in the/tmp directory

#find/tmp-size-2m// find files less than 2M in the/tmp directory

(8) to find files based on file permissions

-perm

#find/tmp-perm 755// find files in the/tmp directory where permissions are 755

#find/tmp-perm +222// indicates that only one type of user (owner, group, other) can match write permissions

#find/tmp-perm-222// indicates that all category users must be satisfied with Write permission

(9),-nouser And-nogroup

#find/-nogroup–a–nouser// Search the entire system for files that are neither master nor group (such files are usually dangerous, we should clear them in time as system engineers)

[ Find out the action of execution]

#-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

[[email protected] HEJP] #find/home/hejp/-name "*.test"-exec chmod 777 {} \;

[[email protected] HEJP] #ll/home/hejp/

Total 4

-RWXRWXRWX 1 Rootroot 3 Mar 3 21:10 hello.test

It's important to note Use of {} : Replace found file

#find/tmp-atime +30–execrm–rf {} \; # Delete found more than a few days have not accessed the file

we can also use Xargs to further work on the files found

Fnd/server/backup–name "*.tar.gz" –mtime +7 |xargs RM-RF


This article is from the "Early bird has the worm to eat" blog, please be sure to keep this source http://hejianping.blog.51cto.com/11279690/1750484

One of the common Linux commands: find

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.