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

Summary of Linux find command usage

Dec 14, 2016 pm 05:14 PM

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 {} ;


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)