Home > php教程 > PHP开发 > Summary of Linux find command usage

Summary of Linux find command usage

高洛峰
Release: 2016-12-14 17:14:37
Original
1364 people have browsed it

The find command is one of the most commonly used commands in Linux. Here is a summary of some common uses.

1. Search by file name.
Search for all files ending with txt in the current directory. The second command uses the -exec parameter to perform an operation on all the files found. Pay attention to the format, and there must be no missing spaces or ;. The -name parameter can use regular expressions, such as the second example

find ./* -name "*.txt"
find ./* -name "[ab]*.py"
find ./* -name "*.pyc" -exec rm {} ;

2. Search by modification time
Find files modified on the current day in the current directory. -1 indicates files modified one day ago. -2 means the first two days. find ./* -mtime n n means that the last modification to the file data was n*24 hours ago. +n refers to n days ago, -n refers to within n days (for -mmin refers to n minutes), n refers to the nth day, their meanings are different, pay attention to the distinction.

find ./* -mtime 60 -type f -print
find ./* -mmin -60 -type f -print
find ./* -mmin +60 -type f -print

3. File status changes
Compared with the previous parameter, the basic principle is the same, but the meaning of this parameter is that the permissions of the file are modified. Changing the content and changing the permissions of the file are different. What is meant here is that the data of the file inode is changed, such as the permissions of the file, the owner and other information. cmin indicates that the permissions have been changed in the past 60 minutes, and ctime indicates that the permissions have been modified in the past few days.

find ./* -cmin +60 -type f -print
find ./* -ctime -60 -type f -print

4
Find the last one of -user and -nouser according to the group and user to which the file belongs The command finds all the files of the currently deleted system users. -group and -nogroup have similar functions.

find ./* -user fox
find ./* -nouser

5
find avoids a certain directory and avoids multiple directories. Among them -a means and, -o means 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
-perm option refers to the file access permission

find - perm 755 -print

7
Use 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 the inode number. You can also delete that particular file via rm.

ls -i1 test*
16187429 test-file-name
16187430 test-file-name
find -inum 16187430 -exec mv {} new-test-file-name ;

8
Find the largest file in the current directory 5 files

find . -type f -exec ls -s {} ; | sort -n -r | head -5

9
The following command deletes *.zip files larger than 100M.

find / -type f -name *.zip -size +100M -exec rm -i {} ;


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template