Format of the Find command: Find [-path]-options [-print-exec-ok]
Path
: The directory path to find.
~ Represents the $home directory
. Indicates the current directory
/represents the root directory
-print: Indicates output of the result to standard output
-exec: Executes the shell command given by the parameter to the matching file. The form is command {} \; , note {} and \; There are spaces between
-ok: As with-exec, the difference is that a prompt is given before the command is executed to let the user confirm whether
the
options are commonly used with the following option:
-name Search by name
-perm Install permissions find
-prune no longer found under the currently specified directory
-user File owner to
find-group belongs to group to find
-nogroup find files with no valid owning group
-nouser Find files
with no valid owner -type Search by file type
Here are some simple examples to illustrate the general use of the next find:
1. Search by name
In the current directory and subdirectories, find the TXT file at the beginning of the capital letter
- [[email protected] ~]# find. -name ' [A-z]*.txt '-print
In/etc and its subdirectories, look for files at the beginning of host
- [Email protected] ~]# find/etc-name ' host* '-print
In the $home directory and its subdirectories, find all Files
- [[email protected] ~]# Find ~-name ' * '-print
In the current directory and subdirectories, find the TXT file that is not the beginning of the out
- [email protected]. code]# Find. -name "out*"-prune-o-name "*.txt"-print
2. Search by directory
Search for txt files in subdirectories other than AA in the current directory
- [email protected]. code]# Find. -path "./aa"-prune-o-name "*.txt"-print
Find txt files in the current directory and subdirectories other than AA and BB
- [email protected]. code]# Find.−PATH"./Aa"−o−patH". /bB" -prune-o-name "*.txt"-print
In the current directory, no longer subdirectories, find txt files
- [email protected]. code]# Find. ! -name "."-type d-prune-o-type f-name "*.txt"-print
3. Search by permissions
In the current directory and subdirectories, look for the master with read and write execution, and other files with reading Execute permission
- [[email protected] ~]# find. -perm 755-print
4. Search by Type
In the current directory and subdirectories, locate the symbolic link file
- [email protected]. code]# Find. -type L-print
5. According to the owner and genus Group
Find files that belong to www
- [email protected]. code]# Find/-user www-type F-print
Find files that belong to the main deleted
- [email protected]. code]# Find/-nouser-type F-print
Find files belonging to the group MySQL
- [[Email protected]lhost. code]# Find/-group mysql-type F-print
Find files deleted by user group
- [email protected]. code]# Find/-nogroup-type F-print
6. Search by Time
Find files that have been changed in 2 days
- [email protected]. code]# Find. -mtime-2-type F-print
Find files that have been changed 2 days ago
- [email protected]. code]# Find. -mtime +2-type F-print
Find files that are accessed in a day
- [email protected]. code]# Find. -atime-1-type F-print
Find files that were accessed a day ago
- [email protected]. code]# Find. -atime +1-type F-print
Find files that are changed in the day
- [email protected]. code]# Find. -ctime-1-type F-print
Find a day ago state changed file
- [email protected]. code]# Find. -ctime +1-type F-print
Find files with status changed 10 minutes ago
- [email protected]. code]# Find. -cmin +10-type F-print
7, according to the old and new documents
Find a new file than Aa.txt
- [email protected]. code]# Find. -newer "Aa.txt"-type f-print
Look for older files than Aa.txt
[Plain]View PlainCopy
- [email protected]. code]# Find. ! -newer "Aa.txt"-type f-print
Find newer than aa.txt, older than bb.txt files
- [email protected]. code]# Find. -newer ' Aa.txt '! -newer ' Bb.txt '-type f-print
8. Search by size
Find files that are over 1M
- [email protected]. code]# Find/-size +1m-type F-print
Find files that are equal to 6 bytes
- [email protected]. code]# Find. -size 6c-print
Find files that are less than 32k
- [email protected]. code]# Find. -size-32k-print
9. Execution of Orders
Find Del.txt and delete, prompt confirmation before deleting
- [email protected]. code]# Find. -name ' Del.txt '-ok rm {} \;
Find Aa.txt and back up as Aa.txt.bak
- [email protected]. code]# Find. -name ' Aa.txt '-exec cp {} {}.bak \;
Find Aa.txt Archive compressed to aa.txt.tar.gz and remove Aa.txt
- Find. -name "Aa.txt"-type f-exec tar-zcvf {}.tar.gz {} \; -exec RM-RF {} \; >/dev/null
Use of Find