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

File lookup

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

File lookup and compression

File lookup

Find eligible files on the file system

Locate command: fuzzy check locate, non-real-time need to manually update the database updatedb

-I: case-insensitive search display column locate-I pasSSWd

-n: only the first three columns showing the query results are listed: locate-N3 passwd

-r: to use basic regular expressions, you need to add the r column: locate-r '.conf $'

Find command: real-time lookup tool to complete file lookup by traversing a specified path

-maxdepth: the maximum search directory depth, and the files in the specified directory are level 1

-depth: first process the files in the directory, and then process the specified directory

Show: find / tmp/-maxdepth 2-name wujiancong

-mindepth: view files of no less than depth and no less than the limited content

Show: find / etc-mindepth 4-name .conf

-name: "File name" supports glob function,? , [], [^]

-iname: case-insensitive lookup of "file name"

-inum: search by inode number

-samefile name files with the same inode number

-regex: matches the entire file path in a pattern, not the file name

Show: find / etc-regex ".. sh $"

Search according to the owner and group.

-user username: find the file whose owner is the specified user UID

Show: find-user wjc

-group grpname: find files whose subordinate group is the specified group GID

Show: find-user joe-not-group joe

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

-nouser: find files without owners

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

Find by file type

-type

F: normal file d: catalog file l: symbolic link file

P: pipe file s: socket file b: block device file

C: character device file-empty: empty file or directory

Combination conditions:

And:-an or:-o not:-not!

De. Morgan's law:

(not A) or (not B) = not (An and B)

(not A) and (not B) = not (An or B)

Show:

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

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

Find files with non-user root and non-F beginning under / tmp

: find / tmp (- not-user root-a-not-name'f')

Find based on file size

-size [+ | -] # UNIT

Commonly used units: K, M, Gmail c (byte)

# UNIT: (#-1, #] for example: 6k means (5kpjc6k)

-# UNIT: [05k] for example:-6k means [05k]

+ # UNIT: (#, ∞) for example: + 6k means (6k, ∞)

According to the timestamp:

In terms of "days"

-atime [+ | -] #, access time

#: [#, # + 1)

+ #: [# + 1, ∞]

-#: [0BZ #)

-mtime modification time when the content of the file was last modified

-time when the ctime change time file was last changed

Find / var-mtime-8! (- user root-o-user postfix)

In "minutes"

-amin

-mmin

-cmin

Find based on permissions

Find / tmp-perm 755

Processing action

-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 file: 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, and ask the user 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

When find passes the found files to the command specified later, it finds all the eligible files at once.

Pass to the following command

 does not support pipes because many commands do not support pipes | to pass parameters, xargs is used to generate the parameters of a command, xargs

You can read in the data of stdin and separate the data of stdin into parameters with spaces or carriage returns.

Many  commands cannot accept too many parameters, and command execution may fail. Xargs can solve the problem.

 Note: cases where a file name or other meaning noun contains a space character

Combination of  find and xargs: find | xargs COMMAND

 example:

Ls | xargs rm deletes a large number of files in the current directory

Find / sbin/-perm + 700 | ls-l this command is incorrect

Find / bin/-perm / 7000 | xargs ls-Sl looks for files with special permissions and sorts them

Find / bin/-perm-7000 | xargs ls-Sl what is the difference between this command and the above command?

Find-type f-name ".txt"-print0 | xargs-0 rm is separated by the character nul

Find example

 backs up the configuration file, adding the .orig extension

Find-name ".conf"-exec cp {} {} .orig\;  prompts you to delete temporary files of joe that have existed for more than 3 days

Find / tmp-ctime + 3-user joe-ok rm {}\;  looks in the home directory for files that can be written by other users

Find ~-perm-002-exec chmod omurw {}\; the permissions under  search / data are 644 and the suffix is sh, and the execution permission is increased.

Find / data-type f-perm 644-name "* .sh"-exec chmod 755 {}\;  View the directory of / home

Find / home-type d-ls

Compression and decompression tool

Zip:

Gzip,gunzip=gunzip-dcentine zcat: use gzip compression to view compressed content using zcat

Bzip2,bunzip2

Xz,unxz

Specify compression ratio: 1-9 levels, with a default of 6 and a maximum of 9

The higher the compression ratio, the slower the speed, and the more cpu resources are consumed.

Gzip compressed file shows that the default compressed .gz suffix of the original file is not retained after gzip message compression is completed.

-c: output the compressed result, which can be saved as a compressed file using redirection, thus retaining the source file

Bzip2: do not keep the original file after the compression is completed. Gz

-k: keep the source file when you compress and decompress

Xz: compression

Archiving tool

Tar [options] file.tar file1

Tar-cvf etc.gz / tmp creation

Tar xvf: decompression

-c: create an archive

-x: expand the archive

-t: view the archived file directly without expanding it

-z: use gzip compression

-Z: decompress with compress

-j: use bz2 compression

-J: use xz compression

-v: displays the execution process of decompression

-f: specify the file name to process

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

Servers

Wechat

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

12
Report