Home >Operation and Maintenance >Linux Operation and Maintenance >How to use the find command under linux

How to use the find command under linux

王林
王林Original
2020-10-22 11:39:209321browse

How to use the find command under Linux: [# find . -name "*.c"], which means to list all files with the extension file name c in the current directory and its subdirectories. The find command is used to find files in the specified directory.

How to use the find command under linux

#The Linux find command is used to find files in the 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 found subdirectories and files will be displayed.

(Recommended tutorial: linux video tutorial)

Grammar

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

Parameter description:

find Judge path and based on the following rules expression, the part before the first - ( ), ! on the command line is path, and the part after it is expression. If path is an empty string, the current path is used. If expression is an empty string, -print is used as the default expression. There are as many as twenty or thirty options that can be used in

expression. 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: In the past n minutes Read

-anewer file: File that was read later than file file

-atime n: File that was read in the past n days

-cmin n: Modified in the past n minutes

-cnewer file: File newer than file file

-ctime n: File modified in the past n days

-empty: empty file -gid n or -group name: gid is n or group name is name

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

-name name, -iname name: File name matching name. iname will ignore case

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

-type c: The file type is c.

d: Directory

c: Font installation file

b: Block installation file

p: Named storage array

f: General file

l: Symbolic link

s: socket

-pid n: File whose process id is n

Example:

List all files with extension c 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 files in the current directory and its subdirectories that have been updated in the last 20 days

# find . -ctime -20

Find ordinary files in the /var/log directory that were changed more than 7 days ago and ask them before deleting them:

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

Related tutorials: linux tutorial

The above is the detailed content of How to use the find command under linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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