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

Format and usage of find command

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

Share

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

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

Common parameters:

Name filename # find a file named filename-perm # find by execute permission-user username # find by file owner-group groupname # find by group

-mtime-n + n # find files according to the time when the files are changed.-n refers to within n days, + n refers to n days ago.

-atime-n + n # check GIN: 0px "> by file access time

-ctime-n + n # find the file by the time it was created.-n refers to within n days, and + n refers to n days ago.

-nogroup # check that there is no valid group file, that is, the file group does not exist in / etc/groups

-nouser # check the file for which there is no valid owner, that is, the owner of the file is not saved in / etc/passwd

-newer F1! f2 look for files.-n refers to within n days, + n refers to n days ago.

-ctime-n + n # find the file by the time it was created.-n refers to within n days, and + n refers to n days ago.

-nogroup # check that there is no valid group file, that is, the file group does not exist in / etc/groups

-nouser # check the file for which there is no valid owner, that is, the owner of the file is not saved in / etc/passwd

-newer F1! f2 # check for files whose change time is newer than F1 but older than f2

-type b/d/c/p/l/f # check for block devices, directories, character devices, pipes, symbolic links, ordinary files

-size n [c] # look up files of length n blocks [or n bytes]

-depth # causes the lookup to find the local directory before entering the subdirectory

-fstype # check for files whose change time is newer than F1 but older than f2

-type b/d/c/p/l/f # check for block devices, directories, character devices, pipes, symbolic links, ordinary files

-size n [c] # look up files of length n blocks [or n bytes]

-depth # causes the lookup to find the local directory before entering the subdirectory

-fstype # look for files located in a certain type of file system, which can usually be found in / etc/fstab

-mount # do not cross the file system mount point when looking up files

-follow # if you encounter a symbolic link file, track the file% that the link refers to

-cpio # look for files located in a certain type of file system, which can usually be found in / etc/fstab

-mount # do not cross the file system mount point when looking up files

-follow # if you encounter a symbolic link file, track the file that the link refers to

-cpio # uses the cpio command on matching files to back them up to the tape device

-prune # ignore a directory

Find usage:

1. Look up by name:

Example: look for files at the beginning of host in / etc and its subdirectories

two。 Search according to the owner and group.

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

-group GRPNAME: find files that belong to the 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

Example: look for files whose owner is www

3. Look up by file 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

Example: find symbolic link files in the current directory and subdirectories

4. Find according to the combination condition:

And:-a

Or:-o

Non:-not!

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

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

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

5. Look up according to the file size:

-size [+ | -] # UNIT

Common units: K, M, G

# UNIT: #-1, #]

-# UNIT: [0memorie muri 1]

+ # UNIT: (# oo)

Example: find files with more than 1m

6. According to the timestamp:

In terms of "days"

-atime [+ | -] #

#: [#, # + 1)

+ #: [# + 1Poweroo]

-#: [0BZ #)

-mtime

-ctime

Example: find files that were changed 2 days ago

In minutes:

-amin

-mmin

-cmin

Example: find files whose status was changed 10 minutes ago

7. 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

Example: in the current directory and subdirectories, find the files for which the owner has read-write execution and other files have read-write permission.

8. 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