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

[CommandDetail] Locate find

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Find eligible files on the file system

File lookup: locate, find

Non-real-time lookup (database lookup): locate

Real-time search: find

Locate:

Rely on pre-built indexes; index construction is done automatically when the system is idle (periodic tasks); update the database manually (updatedb)

The index building process requires traversing the entire root file system, which consumes a lot of resources.

Job characteristics:

Search speed is fast.

Fuzzy search

Non-real-time search

Locate KEYWORD

Find:

Real-time lookup tool to complete file lookup by traversing the file system under the specified path

Job characteristics:

The speed of searching is a little slower.

Precise search

Real-time search

Syntax:

Find [OPTION]... [search path] [search condition] [processing action]

Find path: specify a specific target path; default is the current directory

Search criteria: specified search criteria, such as file name, size, type, permissions, etc.; default is to find all files under the specified path

Processing actions: what to do with qualified files; default output to the screen

Search criteria:

Look up by file name:

-name "file name": glob is supported

*, [], [^]

-iname "file name": case-insensitive

-regex "PATTERN": matches the entire file path string with PATTERN, not just the file name

Look up according to the owner and group:

-user USERNAME: find files whose owner is the specified user

Group GRPNAME: find files that belong to a specified group

-uid UserID: find the file whose owner is the specified UID number

-gid GroupID: find files with the specified GID number in the group

-nouser: find files without owners

-nogroup: find files that do not belong to a group

Look up by file type:

-type TYPE:

F: ordinary files

D: catalog file

L: symbolic link file

S: socket file

B: block device file

C: character device file

P: pipe fil

Combination conditions:

And:-a

Or:-o

Non:-not!

! a-a! B =! (a-o B)

! a-o! B =! (a-a-B)

Find out the files in the / tmp directory where the owner is not root and the file name is not fstab

Find / tmp\ (- not-user root-a-not-name 'fstab'\)-ls

Find / tmp-not\ (- user root-o-name 'fstab'\)-ls

Look up according to the file size:

-size [+ | -] # UNIT

Common units: K, M, G

# UNIT: #-1, #]

-# UNIT: [0memorie muri 1]

+ # UNIT: (# oo)

According to the timestamp:

In terms of "days"

-atime [+ | -] #

#: [#, # + 1)

+ #: [# + 1Poweroo]

-#: [0BZ #)

-mtime

-ctime

In minutes:

-amin

-mmin

-cmin

Find based on permissions:

-perm [/ | -] MODE

MODE: exact permission matching

/ MODE: only one of the permissions of any kind of object can match.

-MODE: each type of object must also have the permission standard specified for it

Processing actions:

-print: default processing action, displayed to the screen

-ls: similar to the "ls-l" command on the found file

-delete: delete the found file

-fls / path/to/somefile: the long format information of all found files is saved to the specified file

-ok COMMAND {}\; execute the command specified by COMMAND for each file found

The user is asked to confirm interactively before executing the command for each file

-exec COMMAND {}\; execute the command specified by COMMAND for each file found

{}: used to reference the found file name itself

Note: when find passes the found files to the command specified later, all the files that meet the criteria will be passed to the following command at once.

Some commands cannot accept too many parameters, and command execution may fail; another way to circumvent this problem:

Find | xargs COMMAND

Exercise:

1. Find all files or directories under the / var directory whose main is root and whose group is mail.

# find / var-user root-group mail

2. Find all files or directories in the / usr directory that do not belong to root, bin or hadoop

# find / usr-not-user root-a-not-user bin-a-not-user hadoop

# find / usr-not\ (- user root-o-user bin-o-user hadoop\)

3. Find a file or directory under the / etc directory that has been modified within the last week, and is not owned by root or hadoop.

# find / etc-mtime-7-a-not-user root-a-not-user hadoop

# find / etc/-mtime-7-a-not\ (- user root-o-user hadoop\)

4. Find files or directories that have no owners or groups on the current system and have been accessed in the most recent week

# find /-nouser-a-nogroup-a-atime-7

5. Find all files in the / etc directory that are larger than 1m and whose types are ordinary files

# find / etc-size + 1m-type f

6. Find files in the / etc directory that all users do not have write permission to

# find / etc-not-perm / 222

7. Find at least one class of files in the / etc directory that the user does not have the right to execute.

# find / etc-not-perm-111l

8. Find files under the / etc/init.d directory where all users have execute permission and other users have write permission

# find / etc/init.d-perm-113

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

Internet Technology

Wechat

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

12
Report