Find 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] images]# find/etc//tmp//root-name passwd
It is important to note that spaces are separated between directories.
[ Find rules ]
(1) Search by file name
#-name // Search by file name (exact search)
#-iname// Search by file name, but not case sensitive
here is another introduction to the name of the knowledge of the wildcard
* indicates a wildcard of any character
[[email protected] ~]# Find/-name "*.img"
? Indicates the wildcard of any single character
[Email protected] ~]# find/etc/-name "PASSW?
[] denotes any one of the characters in the wildcard brackets
[[email protected] ~]# Find/-name "[ab].sh"
(2) Find files based on the users and groups they belong to
#-user// search for files based on owner
#-group// search for files by genus Group
(3) Find users based on uid and GID
#find/tmp-uid// find uid is a file of
#find/tmp-gid// find gid is a file of
(4) Find files based on the relevant attributes of the file timestamp
We can use the Stat command to view the time information for a file as follows:
#-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",Amin the units are minutes
#find/tmp–atime +5// to find files that have not been accessed within five days
#find/tmp-atime-5// to find files that have been accessed within five days
(5) 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
(6) Search for 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
(7) Find files based on file permissions
-perm
#find/tmp-perm 755//Find a file in the/tmp directory with permissions of 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
(8)-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 it and use LS to show 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
Here is the use of {} : replace the found file
#find/tmp-atime +30–exec rm–rf {} \; # Delete found more than a few days have not accessed the file
Example: Find files owned by all users student and copy them to the/root/findfiles directory
[Email protected] ~]# Mkdir/root/findfiles
[[email protected] ~]# Find/-user student-type f-exec cp-p {}/root/findfiles/\;
Or
[Email protected] ~]# cp-p
$ (Find/-user student-type f)/root/findfiles/
Summary of usage of the Find (file Lookup) command under Linux