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

Find file lookup

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

File lookup

Look for eligible files on the file system:

Implementation tool: locate,find

Locate:

Build on the implementation of the built index library: / var/lib/mlocate/mlocate.db

Automatic implementation of the system (periodic tasks)

Update the database manually (updatedb)

Working characteristics:

Fast lookup (based on database lookup)

Fuzzy search

Non-real-time search

Locate [OPTION]... PATTERN...

-b: only matches the base name in the path

-c: count the total number of eligible documents

-r:REGEXP

-I: ignore case

-n #: enumerate only the first N matching files

Note: the index building process requires traversing the entire file system, which consumes system resources

Find:

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

Working characteristics:

The speed of searching is a little slower.

Precise search

Real-time search

Usage:

Find [OPTIONS] [find start path] [search condition] [processing action after search]

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

Search criteria: the specified search criteria can be carried out according to file name, size, type, dependency, permissions, etc. The default is to find all files under the specified path.

Processing action: take actions on files that meet the search criteria, such as deletion, etc.; default is output to standard output

Search criteria:

Expressions: options and test

Test: the result is usually Boolean ("true" or "false")

Look up by file name:

-name "pattern"

-iname "pattern"

Support for glob-style wildcards

*, [], [^]

-inum Inode: search according to the Inode number

-samefile NAME: files with the same inode number

-links #: files with # links

-regex pattern: finds the file based on the regular expression pattern, matching the entire path, not its name

Look up according to affiliation:

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

-group GRPNAME: find files that belong to the specified group

-uid UID: find all the files of the UID specified by the owner

-gid GID: find all files of the GID specified by the group

-nouser: find files without owners

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

Look up by file type:

-type TYPE: finds files based on the specified file type

F: ordinary files

D: catalog file

L: link file

P: pipe fil

S: socket file

B: block device file

C: character device file

Exclude directories:

Find / etc-path'/ etc/sane.d'-a-prune

Combined testing:

And:-a, default combinational logic

Or:-o

Non:-not.not!

Morgan's law:

ALL=123456789

Aids 123, Aids 456789.

Bamboo 345 Bond 126789

A ∩ Barrier 3

A ∪ Bamboo 12345

! a ∩! Bang 6789

! a ∪! Bamboo 12456789

! a ∪! bread! (a ∩ B)

! a ∩! bread! (a ∪ B)

Look up according to the size of the file:

-size [+ | -] # UNIT

Commonly used unit: KTHERMAL MMAG

# UNIT: (#-1 UNIT #]

-# UNIT: [0memorie muri 1]

+ # UNIT: (# oo)

Find based on the timestamp:

Search in terms of "days":

-atime [+ | -] #

#: [#, # + 1]

-#: [#, 0]

+ #: [oo,#]

-mtime

-ctime

Find in "minutes":

-amin

-cmin

-mmin

Find based on permissions:

-perm [/ | -]] mode

Mode: exact permission matching

/ mode: the satisfaction of any one of the permissions of any type of user (umeme gpeno) (rmaine wpjol x)

There is an OR relationship between 9-bit permissions.

-mode: the satisfaction of each of the permissions of each type of user (umeme gpeno) at the same time (rmae wpjol x)

There is a "and" relationship between 9-bit permissions.

Processing actions:

-print: output to standard output; default action

-ls: similar to executing the "ls-l" command on the found file to output the details of the file

-delete: delete the found file

-fls / PATH/TO/SOMEFILE: saves the long format information of all found files to the specified file

-ok COMMAND {}\;: execute the COMMAND command for every file found; each operation is confirmed by the user

-exec COMMAND {}\;: execute the command represented by COMMAND for each file found; modify it directly

Note: when find passes the found file path to the following command, it first finds out all the qualified file paths and passes them to the following command at one time

However, some commands cannot accept excessively long parameters, and the execution of the command will fail. There is another way to avoid the secondary 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-a-group mail

two。 Find all files or directories in the / usr directory that do not belong to root,bin or hadoop; in two ways

Find / usr/-not-user root-a-not-user bin-a-not-user hadoopfind / usr/-not\ (- user root-o-user bin-o-user hadoop\)

3. Find files or directories under the / etc directory whose contents have been modified in the last week and whose owner is neither a root user nor a hadoop user

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 do not have an owner or group on the current system and have been accessed in the last week

Find /\ (- nouser-o-nogroup-a-atime-7\)

5. Find all files in the / etc directory that are larger than 1m and have a normal file type

Find / etc/-size + 1m-a-type f

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

Find / etc/-not-perm / 222-ls

7. Look for files in the / etc directory that have at least one class of users that do not have execute permissions

Find / etc/-not-perm-111111-ls

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

Find / etc/init.d/-perm-113

9./tmp directory, not a directory, and cannot be a socket type file yet

Find / tmp/-not-type d-a-not-type sfind / tmp/-not\ (- type d-o-type s\)

Under the 10./tmp/ directory, the owner is not a user1 or a file that is not a directory

Find / tmp/\ (- not-user user1-o-not-type d\) find / tmp/-not\ (- user user1-a-type d\)

11. Find files that have no owner or array on the current system and have been accessed in the last 1 day, and modify the master array to root

Find /\ (- nouser-o-nogroup-a-atime-1\)-exec chown root:root {}\

twelve。 Find files larger than 1m in the / etc directory and write their filenames to the / tmp/etc.largefiles file

Find / etc/-size + 1m > / tmp/etc.largefiles

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