Linux find command usage Summary
The find command is one of the most common commands in Linux. Here are some common usage summaries.
1. Search by file name.
Search for all files ending with txt in the current directory. The second command uses the-exec parameter. You can execute an operation on all the files to be searched. Pay attention to the format, space and; no less. -The name parameter can be a regular expression, for example, the second example.
Find./*-name "*. txt"
Find./*-name "[AB] *. py"
Find./*-name "*. pyc"-exec rm {}\;
2. Search by modification time
Find the files modified on the current day in the current directory. -1 indicates the File Modified one day ago. -2 indicates the previous two days. Find./*-mtime n indicates that the last modification to the file data was before n * 24 hours. + N refers to n days ago,-n refers to n days or less (-mmin refers to n minutes), and n indicates the nth day. Their meanings are different.
Find./*-mtime 60-type f-print
Find./*-mmin-60-type f-print
Find./*-mmin + 60-type f-print
3. File status changes
The basic principle is the same as that of the previous parameter, except that the File Permission is modified. The permission to modify the content is different from the permission to change the file. Here, the permission to change the inode data of the file, such as the File Permission and owner information. Cmin indicates that the permission has been changed in the last 60 minutes, and ctime indicates that the permission has been modified in the last few days.
Find./*-cmin + 60-type f-print
Find./*-ctime-60-type f-print
4
Search for the last-user and-nouser commands based on the group and user of the file to find all the files of the System user that has been deleted. The functions of-group and-nogroup are similar.
Find./*-user fox
Find./*-nouser
5
Find avoids a directory and avoids multiple directories. Where-a indicates and, and-o indicates or.
Find test-path "test/test4"-prune-o-print
Find test \ (-path test/test4-o-path test/test3 \)-prune-o-print
Find. \ (-path. /modules-o-path. /framework-o-path. /utils-o-path. /config \)-prune-o-name "Bigger. * "-print
6
-The perm option indicates the object access permission.
Find-perm 755-print
7
Utility inode to find the file number. The inode number can be specified in the find command as shown below. Here, the find command renames a file with an inode number. You can also use rm to delete the special file.
Ls-i1 test *
16187429 test-file-name
16187430 test-file-name
Find-inum 16187430-exec mv {} new-test-file-name \;
8
Find the maximum five files in the current directory
Find.-type f-exec ls-s {}\; | sort-n-r | head-5
9
The following command deletes the *. zip file larger than MB.
Find/-type f-name *. zip-size + 100 M-exec rm-I {}\;
Find a file in Linux
Detailed description of the find command in Linux
Use of find, a text search tool
Powerful find command
Detailed description of the find command in Linux
This article permanently updates the link address: