Linux find command complete

Common usage examples of find in Linux
: find path -option [ -print ] [ -exec -ok command ] {} \;
The parameters of the find command;

pathname: the directory path searched by the find command. For example, use . to represent the current directory and / to represent the system root directory.
-print: The find command outputs matching files to standard output.
-exec: The find command executes the shell command given by this parameter to the matching files. The corresponding command is of the form 'command' { } \;, note the space between { } and \;.
-ok: The same as -exec, except that the shell command given by this parameter is executed in a safer mode. Before executing each command, a prompt will be given to let the user determine whether to execute it.

#-print will output the found file to standard output
#-exec command {} \; ——– will execute the command operation on the found file, there is a space between {} and \;
#-ok is the same as -exec, except Ask the user before operation

Example : find . -name .svn | xargs rm -rf
================================= ======================

-name filename #Find a file named filename
-perm #Search by execution permission
-user username #Search by file owner
-group groupname #Search by group
-mtime -n +n #Search by file change time, -n means within n days, +n means n days ago
-atime -n +n #Search GIN by file access time: 0px">

-ctime -n +n #Search files by file creation time, -n means within n days, +n means n days ago

-nogroup #Check no valid group The file, that is, the group of the file does not exist in /etc/groups
-nouser #Check the file without a valid owner, that is, the owner of the file does not exist in /etc/passwd
-newer f1 !f2 Find the file, -n Refers to within n days, +n refers to n days ago
-ctime -n +n #Find files according to the file creation time, -n refers to within n days, +n refers to n days ago
-nogroup #Search for files with no valid group, That is, the group of the file does not exist in /etc/groups
-nouser #Check the file without a valid owner, that is, the owner of the file does not exist in /etc/passwd
-newer f1 !f2 #Check the change time is newer than f1 but files older than f2
-type b/d/c/p/l/f #Check is block device, directory, character device, pipe, symbolic link, ordinary file
-size n[c] #Check length is n blocks [or n bytes] File
-depth #Make the search complete this directory before entering the subdirectory
-fstype #Check the file whose change time is newer than f1 but older than f2
-type b/d/c/p/l/f #Check if it is a block device, Directories, character devices, pipes, symbolic links, ordinary files
-size n[c] #Check files with a length of n blocks [or n bytes]
-depth #Make the search complete this directory before entering subdirectories
-fstype # Check files located in a certain type of file system, these file system types can usually be found in /etc/fstab
-mount #Do not cross the file system mount point when checking files
-follow #If you encounter a symbolic link file, follow the link Refers to the file
-cpio %; #Check files located in a certain type of file system, these file system types can usually be found in /etc/fstab
-mount #Check files without crossing the file system mount point
-follow #If a symbolic link file is encountered, follow the file pointed to by the link
-cpio #Use the cpio command on the matching files to back them up to a tape device
-prune #Ignore a directory
======== ===============================================
$find ~ -name "*.txt" -print #Check for .txt files in $HOME and display
$find . -name "*.txt" -print
$find . -name "[AZ]*" -print #Check for files starting with uppercase letters File
$find /etc -name "host*" -print #Check for files starting with host
$find . -name "[az][az][0–9][0–9].txt" -print #Check for txt files starting with two lowercase letters and two numbers
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} \; #Check the files that all users can read, write and execute with -perm 777
$find . -type d -print
$find . ! -type d -print
$find . -type l -print

$find . -size +1000000c -print #Check files with length greater than 1Mb
$find . -size 100c -print # Check files with length 100c
$find . -size +10 -print #Check A file whose length exceeds the expiration date is 10 blocks (1 block = 512 bytes)

$cd /
$find etc home apps -depth -print | cpio -ivcdC65536 -o /dev/rmt0
$find /etc -name "passwd*" -exec grep "cnscn" {} \; #See if there is a cnscn user
$find . -name "yao*" | xargs file
$find . -name "yao*" | xargs echo "" > /tmp/core.log
$find . -name "yao*" | xargs chmod ow

========================================= =============

find -name april* Find files starting with april in the current directory
find -name april* fprint file Find files starting with april in the current directory and output the results to file
find -name ap* -o -name may* Find files starting with ap or may
find /mnt -name tom .txt -ftype vfat Find a file named tom.txt under /mnt with a filesystem type of vfat
find /mnt -name t.txt ! -ftype vfat Find a file named tom.txt under /mnt with a different filesystem type Find the file of vfat
/tmp -name wa* -type l Find the file whose name starts with wa and the type is a symbolic link in /tmp
find /home -mtime -2 Find the file that has been changed in the last two days in /home
find /home -atime -1 Check the files that have been accessed within 1 day
find /home -mmin +60 Check the files under /home that were changed 60 minutes ago
find /home -amin +30 Check the files that were saved 30 minutes ago Fetched files
find /home -newer tmp.txt Find files or directories under /home with a newer update time than tmp.txt
find /home -anewer tmp.txt Find files or directories under /home whose access time is closer than tmp.txt
find /home -used -2 ​​List files or directories that have been accessed within 2 days after they have been changed file or directory
find /home -user cnscn List the files or directories belonging to the user cnscn in the /home directory
find /home -uid +501 List the files or directories with the user ID greater than 501 in the /home directory
find /home -group cnscn List files or directories with group cnscn in
/home find /home -gid 501 List files or directories with group id 501 in
/home find /home -nouser List files or directories in /home that do not belong to local users
find /home -nogroup List files or directories in /home that do not belong to a local group
find /home -name tmp.txt -maxdepth 4 List tmp.txt in /home The depth of the search is up to 3 levels
find /home -name tmp.txt -mindepth 3 starts from layer 2
find /home -empty Find files with size 0 or empty directories
find /home -size +512k Find files larger than 512k
find /home -size -512k Find files smaller than 512k
find /home -links +2 Check the number of hard links greater than 2 files or directories
find /home -perm 0700 Check files or directories whose permissions are 700
find /tmp -name tmp.txt -exec cat {} \;
find /tmp -name tmp.txt -ok rm {} \;

find / -amin -10 # Find files accessed in the system in the last 10 minutes
find / -atime -2 # Find files accessed in the system in the last 48 hours
find / -empty # Find files or folders that are empty in the system
find / -group cat # Find files that belong to groupcat in the system
find / -mmin -5 # Find files modified in the last 5 minutes in the system
find / -mtime -1 #Find files modified in the system in the last 24 hours
find / -nouser #Find files belonging to invalid users in the system
find / -user fred #Find files belonging to the user FRED in the system

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326352043&siteId=291194637