English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux find command

Linux Command大全

The Linux find command is used to search for files in a specified directory. Any string before the parameters is considered as the name of the directory to be searched. If no parameters are set when using this command, then find The command will search for subdirectories and files in the current directory. It will display all the found subdirectories and files.

Syntax

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

Parameter Description :

find determines path and expression according to the following rules, the first one in the command line - ( ) , ! The part before ( ) is path, and the part after is expression. If path is an empty string, the current path is used. If expression is an empty string, it uses -print is the default expression.

There are more than twenty or thirty options available in expression, but only the most commonly used ones will be introduced here.

-mount, -xdev : Only checks files in the same filesystem as the specified directory, avoiding files from other filesystems

-amin n : Files accessed in the last n minutes

-anewer file : Files accessed more recently than file

-atime n : Files accessed in the last n days

-cmin n : Files modified in the last n minutes

-cnewer file : Files newer than file

-ctime n : Files modified in the last n days

-empty : Empty files-gid n or -group name : gid is n or the group name is name

-ipath p, -path p : Files whose path names match 'p', ipath ignores case.

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

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

-type c : The file with file type is c.

d: directory

c: character device file

b: block device file

p: named pipe

f: general file

l: symbolic link

s: socket

-pid n : The file with 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

Online Examples

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

# find . -name "*.c"

List all general files in the current directory and its subdirectories:

# find . -type f

List all recent files in the current directory and its subdirectories: 2Files updated within 0 days listed:

# find . -ctime -20

Find /var/The change time in the log directory is 7 Files of type f older than n days, and ask before deleting them:

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

Find files in the current directory with read/write permissions for the owner and read permissions for users in the group and other users:

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

Find all regular files with length of 0 in the system and list their complete paths:

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

Linux Command大全