Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the common command find in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use the commonly used Linux command find for you. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

The Linux common command ind command is used to find files in a specified directory. Any string that precedes a parameter is treated as the name of the directory you are looking for. If you use this command without setting any parameters, the find command looks for subdirectories and files under the current directory.

Syntax find path-option [- print] [- exec-ok command] {}\; Parameter description:

Find judges path and expression according to the following rules, the first-(), on the command line! The first part is path, followed by expression. The current path is used if the path is an empty string, and-print is used as the default expression if the expression is an empty string.

There are as many as 20 or 30 options available in expression, and only the most commonly used ones are introduced here.

-mount,-xdev: only check and specify files in the same file system to avoid listing files in other file systems

-amin n: read in the past n minutes

-anewer file: a file that was read later than the file file

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

-cmin n: modified in the past n minutes

-cnewer file: files that are newer than the file file

-ctime n: files that have been modified in the past n days

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

-ipath p,-path p: files whose path names match p. Ipath ignores case.

-name name,-iname name: a file whose name matches name. Iname ignores case

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

-type c: a file of type c.

D: directory

C: font device file

B: block device file

P: named storage column

F: general documents

L: symbolic link

S: socket

-pid n: process id is the file of n

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

Exp1-and exp2

! Expr

-not expr

Exp1-or exp2

Exp1, exp

Instance lists all files under the current directory and its subdirectories with the suffix .c:

# find. -name "* .c" lists all general files in its subdirectories of the current directory

# find. -type f lists all files that have been updated in the last 20 days under the current directory and its subdirectories:

# find. -ctime-20 look for ordinary files in the / var/log directory that were changed before 7 days, and ask them before deleting them:

# find / var/log-type f-mtime + 7-ok rm {}\; find files in the current directory where the file owner has read and write permissions, and the users of the group to which the file belongs and other users have read permissions:

# find. -type f-perm 644-exec ls-l {}\; find all normal files in the system with a length of 0 and list their full paths:

# find /-type f-size 0-exec ls-l {}\; this is the end of the article on "how to use Linux commands find". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report