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

How to use the find command under linux

王林
Release: 2020-10-22 11:39:20
Original
9349 people have browsed it

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 ]   {} \;
Copy after login

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"
Copy after login

List all general files in the current directory and its subdirectories

# find . -type f
Copy after login

List all files in the current directory and its subdirectories that have been updated in the last 20 days

# find . -ctime -20
Copy after login

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 {} \;
Copy after login

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!

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template