Linux system find command is very useful and convenient when searching for files. It can find files based on different criteria, such as permissions, owner, modification date / time, file size, and so on.
The basic syntax of the find command is as follows:
$ find [path] [option] [expression]
-print: the output file will match the find command to standard output.
-exec: find command to execute shell commands given by the parameter file match. Form of these commands to 'command' {} \ ;, and attention {} \; space between.
-name filename # find a file called filename.
-user username # Press to locate the file owner.
-type b / d / c / p / l / f # search block device, directory, character devices, pipes, symbolic links, normal file.
-size n [c] # search block length n [n bytes or] file
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
find ~ -name "* .txt" -print # and displayed in HOME check .txt file
the Find $. -name "* .txt" -print
$ the Find. -name "[AZ] *" -print # check to begin with a capital letter file
$ find / etc -name "host * " -print # search begins with host files
$ find. -name "[az] [az] [0-9] [0-9] .txt" -print # to check the first two lowercase letters and two numbers txt file
$ find. -perm 755 -print
$ LS Find -perm -007 -exec {} -l \;. # search all users with read-write execution file 777 -perm
$ D -print Find -type.
$ D -print Find -type.!
Find $. -type L -print
$ Find. -print -size + 1000000c check # of length greater than 1Mb file
$ find. -size 100c -print # check the length of a file 100c
$ find. -size +10 -print # Zha a length of more than 10 is obsolete file (one block = 512 bytes)
$ CD /
$ etc Find Home Apps -depth -print | -ivcdC65536 the cpio -o / dev / rmt0
$ Find / etc -name "* the passwd" -exec grep "cnscn" {} \; # user to see whether there cnscn
$ find.-name "yao*" | xargs file
the Find -name $ "yao *" |. xargs echo ""> /tmp/core.log
. $ the Find -name "yao *" | xargs chmod OW
================ ======================================
the Find -name * look for april april in the current directory beginning of the file
find -name april * fprint file to find the file to the beginning of april in the current directory, and outputs the result to file
find -name ap * -o -name may * look for ap or file may begin with
find / mnt -name tom.txt -ftype vfat look up the name in / mnt as tom.txt and the file system type vfat file
find / mnt -name t.txt! -ftype vfat look up the name in / mnt and the file is tom.txt the system type is not vfat file
find / tmp -name wa * -type l find a file named wa at the beginning and it's a symbolic link in the / tmp
the Find / home -mtime -2 check in / home altered in the last two days file
find / home -atime -1 checked had been accessed within 1 day files
find / home -mmin +60 checked 60 minutes before the altered file in / Home
Find / Home -amin +30 check latest 30 minutes before being accessed file.
find / home -newer tmp.txt at / home update check time than near the file or directory tmp.txt
find / home -anewer tmp.txt at / home check access time than near the file or directory tmp.txt
find / home -2-Used List file or directory is altered after 2 days accessed through the file or directory
find / home -user cnscn belonging to the user are listed in cnscn / home directory file or directory
find / home - uid +501 listed in the / home directory of the user identification code 501 is greater than the file or directory
find / home -group cnscn lists / home cnscn the group of files or directories
listed / home the group id find / home -gid 501 501 for the file or directory
find / home -nouser are not listed in the local user / home file or directory
find / home -nogroup not listed in the local group / home file or directory
find / home -name tmp.txt tmp.txt listed in -maxdepth 4 / home when the depth of investigation of up to 3 layers
find / home -name tmp.txt -mindepth 3 from the second layer began to check
find / home -empty size of the lookup file or empty 0
find / home -size + 512k 512k greater than the search file
find / home -size -512k check the files smaller than 512k
find / h ome -links +2 check hard file or directory number of connections is greater than 2,
find / home -perm 0700 700 check permissions for the file or directory
Find / tmp -name tmp.txt CAT -exec {} \;
Find / tmp -name tmp.txt -OK RM {} \;
Find / -amin -10 # Find access system in the last 10 minutes of the file
find / -atime -2 # Find access the last 48 hours in a file system
find / -empty # find empty in the system file or folder
find / -group cat # groupcat find files that belong in the system
find / -mmin -5 # Find the last five minutes of the modified file in the system
find / -mtime -1 # search the last 24 hours in the modified file system
find / -nouser # Find void user in the system belong to a file
find / -user fred # find FRED belong to this file in the user's system
to view all the regular files in the current directory
# Find -type -exec LS -l {F} \;.
- R-. 1-R & lt-RW the root 12959 2003-02-25 ./conf/magic the root
-rw the root. 1-R & lt R--180 [2003-02-25 ./conf.d/README the root
check all common in the current directory file and - using the command exec ls -l option to list them
================================= ================
Find time to change the file before the 5th in / logs directory and delete them:
$ logs the Find The -type f -exec -mtime +5 -ok RM {} \;
============= ====================================
query modified date that the file
[root @ book class] # find F -1 -type -exec -mtime ./ LS -l {} \;
================================ =================
query file and asks if you want to display
[root @ book class] # find ./ -mtime -1 -type f -ok ls -l {} \;
? <LS ... ./classDB.inc.php> the y-
-rw-r-R- 1 cnscn cnscn 13709 1 Yue 12:22 ./classDB.inc.php 12
[root @ Book class] # ./ -mtime the Find - F -OK LS -l -type. 1 {} \;
<./classDB.inc.php LS ...> n-?
[@ Book the root class] #
================= ================================
inquiry and handed over to deal with awk
[root @ book class] # who | awk ' Print. 1 $ { "\ T" $ 2} '
cnscn PTS / 0
=================================================
awk Sed--grep
[@ Book the root class] DF # -k | awk '{}. 1 Print $' | grep -v 'none' | Sed S "/ \ / dev \ /// G"
file system
sda2
sda1
[the root @ book class] # df -k | awk '{print $ 1}' | grep -v 'none'
the file system
/ dev / sda2
/ dev / sda1