Linux find command file search find /usr/local/log -type f -mtime +7 rm {} \;

Linux find command file search find /usr/local/log -type f -mtime +7 rm {} \;

The Linux find command is used to find files in a specified directory. Any string preceding the parameter will be treated as the name of the directory to be searched. If you use this command without setting any parameters, the find command will search for subdirectories and files in the current directory. And all the found subdirectories and files will be displayed.

grammar:

find   path   -option   [   -print ]   [ -exec   -ok   command ]   {
    
    } \;

Parameter Description :

findpathJudging and according to the following rules expression, the part before the first on the command line - ( ) , !is path, and the part after is expression. If pathis an empty string, use the current path, if expressionis an empty string, use -print as the default expression.

expressionThere are twenty or thirty options available in , and only the most commonly used ones are introduced here.

-mount, -xdev: Only check files in the same file system as the specified directory, avoid listing files in other file systems

-amin n: has been read within the past n minutes

-anewer file: Files that have been read later than file

-atime n: files that have been read in the past n days

-cmin n: Modified within the last n minutes

-cnewer file: a file newer than the file file

-ctime n: files created within the past n days

-mtime n: files modified within the past n days

-empty: empty file -gid n or -group name: gidyes nor groupname isname

-ipath p, -path p: file whose path name matches p, ipath will ignore case

-name name, -iname name: Files whose file names match name. iname ignores case

-size n: The file size is in units of n, b represents a block of 512 bytes, c represents the number of characters, k represents kilo bytes, and w represents two bytes.

-type c: The file type is c file.

d: Table of contents

c: font device file

b: block device file

p: Named storage column

f: General Documents

l: symbolic link

s: socket

-pid n: the file whose process id is n

You can use ( )to separate expressions and use the following operations.

exp1 -and exp2

! expr

-not expr

exp1 -or exp2

exp1, exp2

example

List all files with the suffix in the current directory and its subdirectories .c:

# find . -name "*.c"

List all files in the current directory and its subdirectories:

# find . -type f

List all files updated in the last 20 days in the current directory and its subdirectories:

# find . -ctime  20

Find /usr/local/logordinary files in the directory with a change time older than 7 days, and ask them before deleting:

# find /usr/local/log -type f -mtime +7 -ok rm {} \;

Find files in the current directory whose owner has read and write permissions, and whose group and other users have read permissions:

# find . -type f -perm 644 -exec ls -l {} \;

Find all normal files with a file length of 0 on the system and list their full paths:

# find / -type f -size 0 -exec ls -l {} \;

Guess you like

Origin blog.csdn.net/sunny_day_day/article/details/128452518