Find command, find
The find command is one of the most commonly used commands. 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. Note the format, space, and;
No fewer than one. -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
N indicates that the last modification to the file data is 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 -printfind ./* -mmin +60 -type f -print
3. File status change
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 -printfind ./* -ctime -60 -type f -print
4
Search by file group and user-user
And-nouser
The Last Command finds all the files of the System user that has been deleted,- group
And- nogroup
.
find ./* -user foxfind ./* -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 -printfind 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
-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-name16187430 test-file-namefind -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 +100M -exec rm -i {} \;