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

About file lookup and decompression

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

File lookup and decompression

Find qualified files on the file system. There are two tools for finding files, locate and find.

File lookup is divided into:

Locate non-real-time search (search in database)

Updatedb updates the database

Often used to search for stable files, such as configuration files

Var/lib/mlocate/mlocate.db database path

Find real-time search

Locate:

Query the pre-built file index database on the system

/ var/lib/mlocate/mlocate.db

Depends on the index that is built; the index is built automatically when the system is idle (periodic tasks)

The administrator can update the database updatedb manually

The index building process requires traversing the entire root file system and consuming resources

Job features: fast search speed

Fuzzy search

Non-real-time accurate search

Search for the full path of the file, not just the file name

It is possible to search only directories where the user has read and execute permissions

Locate option keyword

Locate-I AAA performs a case-insensitive search

Locate-n 2 aa lists only the first few matching items

Locate makangbo searches for files with makangbo in the name or path

Locate-r'\ .bash $'uses regular expressions to search for files ending in bash

Find real-time lookup tool to complete file search by traversing the specified path

Features: accurate search, slow speed, and may only search directories where the user has read and execute permissions

Syntax: find [options] [search path] [search criteria] [processing actions]

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

Search criteria: specified search criteria, which can be carried out by file name, size, type, permissions, etc.; default is all files under the specified path

Processing action: operate on meeting the conditions and output to the screen by default

Search criteria:

Look up based on file name and inode

-name "file" supports the use of regular expressions] # find-name makangbo to search for files named makangbo

*? [] [^] ~] # find /-name "* .txt" searches for files with any character before the root directory that ends with * .txt

-iname "file" is case-insensitive] # find-iname MAkangbo searches for files named makango or MAkangbo that are not case-sensitive

-inum inode search by inode number] # find-inum 5555 node number file search

-samefile filename files with the same inode number

-Files with links links] # find-in-links 5 Files with 6 links

-regex "expression" matches the entire file path string with an expression, not just the file name

-user user name is searched according to the owner of the file.

-group group name is looked up according to the subordinate group of the file

-uid UID looks for files according to UID

-gid GID looks for files according to GID

-nouser looks for files without owners

-nogroup looks for files that do not belong to a group

Look up by file type:

-] # find-user makangbo-type f, for example, find ordinary files under the user

F ordinary file

D directory file

L symbolic link file

S socket file

B block device file

C character device file

P pipe file

Combination condition lookup:

-a vs.

-o or

-not! Non

-not Amura-not B =-not (A-o B) is neither A nor B

-not Amuro-not B =-not (A-a B) is not An or B

! a-a! BA! (a-o B) neither A nor B

! a-O! beer! (a-a-B) not An or B

Note: parentheses need to be escaped\ (\)

De Morgan's law:

Non-P or non-Q = non (P and Q) the first two are not P or not Q, which means no, equal and not (P and Q)

Non-P and non-Q = non-(P or Q) the first two are not P and not Q, that is, both are right and wrong, equal and not (P or Q)

~] # find / var-name "* log*" search / var directory to match any character before and after the search file with the log keyword

~] # find-user makangbo-group makangbo search for files owned by user makangbo and group makangbo

] # find-user makangbo-not-group makangbo searches for files in which the user makangbo group is not makangbo

] # find-user makangbo-o-user root searches the files of user makangbo or user root to meet a condition

] # find-not\ (- user makangbo-o-user root\) search for files that are not related to user makangbo or user root

] # find /-user makangbo-o-uid 500search the files of user makangbo or uid 500in the root directory

] # find / tmp\ (- not-user root-a-not-name "f *"\) find out that in the / tmp directory, the user owner is not root and the file name is not a file that begins with f

] # find / tmp-not\ (- user root-o-name "f *"\) is not a user root or a file that does not start with f

Find based on file size:

~] # find-size + 10k

Commonly used unit: k.m.m.g.

Find-size 10k means between 9k and 10k (9k5m 10k) above the original number-1

Find-size + 10k means that more than 10k does not include 10 infinity (10k, ∞)

Find-size-10k means 0k to 9k including 9k (0prime9k)

According to the timestamp:

In days

~] # find-atime 5

Find-atime 5 means + 1 above the original number for the last 5 to 6 days.

Find-atime + 5 means more than 5 days to infinity (5, ∞)

Find-atime-5 means 0 to 5 days (0-5)

-mtime

-ctime

In minutes

-amin

-mmin

-cmin

Search according to weight:

Exact permission matching of perm [/ | -] mode

~] # find-perm 644

The permissions of any type of user can only include any one of the permissions assigned to them, or relationship, + from version 7 to / or-to indicate and

Find-perm 755 will match files whose right phase mode happens to be 755

Find-perm + 222matches as long as any user has write permission

Find-perm-222indicates that the permissions in each bit match if they are less than or equal to 2.

Find-perm-002will match only if someone else (other) has write permission.

Find-perm-666 includes 666, 650, 550, 111, but not 766, etc.

Find-perm + 621indicates that the owner has read or write, or the group has write, or any other person with executive permission can.

The 0 in-002 does not match the permissions of the owner and the group, rather than saying that the owner and the group do not have any permissions 0 means that they do not care.

Processing actions:

For example, find-perm 2222-print

Suffix with search criteria

-print default processing action, display, print to screen ~] # find F1-print-ls default output print display, even if not added

-ls is similar to executing the ls-l command on the found file ~] # find F1-ls

-delete deletes the found file ~] # find F1-delete deletes the found file directly, without prompting, takes advantage of this command

-fls / path file / long format information of all found files is saved to the specified file ~] # find F1-fls / root/f1.log then a f1.log file is generated, that is, the found command is imported into a specified file; equivalent and redirected file

The-ok command {}\; executes the command specified by the command for each file found

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

Where {} represents all the previously found content references ~] # find F1-ok rm {}\; whether to delete the search content before the reference

-exec command {}\; execute the command specified by the command for each file found without prompting the user to execute ~] # find F1-exec rm {}\; directly without prompting

When find passes the found file to the command specified later, it finds all the eligible files and passes them to the following command at one time.

Some spectators cannot accept too many parameters, and the execution of the command may fail.

You can use this command to circumvent this problem: find | xargs command

~] # find-name "* .sh"-exec cp {} {}. Bak\

Back up the files whose search ends with .sh and add the. bak extension

~] # find / tmp-ctime + 3-user makangbo-ok rm {}\

Prompt to delete temporary files of makangbo users who have been around for more than 3 days

~] # find-perm-002-exec chmod Omurw {}\

Look for files in the home directory that can be written by other users

~] # find / home/-type d-ls

Search for directory files under home

Practice

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

~] # find / var-user root-a-group mail

2. Find all the files in the / var directory that do not belong to root, lp or gdm

~] # find / var-not-user root-a-not-user lp-a-not-user gdm

~] # find / var-not\ (- user root-o-user lp-o-user gdm\)

3. Find files whose contents have been modified in the last week in the / var directory, and the owner is neither root nor xiaomag.

~] # find / var-mtime-7-a-not-user root-a-user xiaomag

~] # find / var-mtime-7-not\ (- user root-o-user xiaomag\)

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

~] # find /-atime-30\ (- nouser-o-nogroup\)

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

Find the path, look for more than 1m according to the size, and find ordinary files

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

~] # find / etc-not-perm + 222-ls

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-22222-ls

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

Decompression and archiving tool

In the early days, there were compress and uncompress, corresponding to compressed format files ending with .Z.

Gzip and gunzip correspond to compressed format files ending with .gz.

Bizp2 and bunzai2 correspond to compressed format files ending with .bz.

Xz and nuxz correspond to compressed format files ending with .xz.

Compressed format file at the end of .zip for zip and unzip

Tar archiving

Cpio packing

Compress and uncompress

Syntax compress options file

Compress file compressed files do not retain the original files

Compress-d file decompression, which equals to uncompress

Compress-c file outputs standard values of compressed or decompressed results, and retains the original file ~] # compress-c file > file.Z

Compress-v file display details

The zcat file.Z > file decompression suffix is Z

Gzip and gunzip

Syntax gzip options file

Gzip-# file # indicates the compression ratio for the number; 1-9. The default is 6. The larger the number, the greater the compression ratio. For example, the maximum compression ratio: gzip-9 file

Gzip-d file.gz unzips the file, which is equivalent to the extracted command gunzip

Gzip-c file outputs the compressed or decompressed results as standard output, keeping the original file

For example, gzip-c file > file.gz is redirected to the file, keeping the original file

Gizp-r file recursively to the directory to compress each file

Zcat file.gz > file do not need to display unzipped to view the contents of the compressed file > can redirect the file

For example, gzip-c-d file.gz > / destination path / file zip file suffix is gz

Bzip2 and bunzip2 / bzcat

Syntax bzip2 options file

Bizp2-# file # indicates the compression ratio for the number; 1-9. The default is 6. The larger the number, the greater the compression ratio. For example, the maximum compression ratio: bzip2-9 file

Keep the original file after bzip2-k file compression

Bzip2-d file unzipped, which is the same as bunzip2 compressed file with the suffix bz2

Bzcat / destination path / file.bz2 does not need to display unzipped to view the contents of the compressed file > can redirect the file

Xz / unxz / xzcat

Syntax xz options file

Xz-# file # indicates the compression ratio for the number; 1-9. The default is 6. The larger the number, the greater the compression ratio. For example, the maximum compression ratio: bzip2-9 file

Keep the original file after xz-k file compression

Xz-d file unzipped, which is the same as bunzip2 compressed file with the suffix xz

Xzcat / destination path / file.xz does not need to display unzipped to view the contents of the compressed file > can redirect the file

Zip / unzip

Packing and compressing

Zip-r file path Source path

Command option generation path source file path can be compressed and archived into a single file with the suffix zip

Unpack and decompress

Unzip file

Performance ranking: xz; bzip; gzip from top to bottom, but gzip is often used

Archiving tool

Archiving is to package multiple files into a single file for easy management, and the default archive does not perform compression.

Commonly used workers have tar; cpio

Syntax tar option file

Create an archive tar

Tar-c-f / PATH/TO/SOMEFILE.tar FILE

Tar cf / PATH/TO/SOMEFILE.tar FILE

~] # tar-c-f / root/f2.tar f2 archive file f2 to f2.tar

Note: archiving does not delete the original file

View a list of files in the archive

~] # tar-t-f / root/f2.tar View the list of files in f2.tar

Expand archiving

~] # tar-x-f / root/f2.tar

~] # tar-x-f / root/f2.tar-C / PATH/

Combined with compression tools: archive and compress

-z gzip

Suffix: .tar.gz

Archive and compress: tar-zcf ~] # tar-zcf / root/f3.tar.gz f3

Expand archiving: tar-zxf ~] # tar-zxf f3.tar.gz

-j bzip2

Suffix: .tar.bz2

Archive and compress: tar-jcf ~] # tar-jcf / root/f3.tar.bz2 f3

Expand archiving: tar-jxf ~] # tar-jxf f3.tar.bz2

-J xz

Suffix: .tar.xz

Archive and compress: tar-Jcf ~] # tar-Jcf / root/f3.tar.xz f3

Expand archiving: tar-Jxf ~] # tar-Jxf f3.tar.xz

Note: you can use tar-xf directly to expand the archive without specifying the corresponding compression tool options.

Cpio archiving files and extracting files from packages

The cpio command is a tool to package and backup files through redirection and restore them. It can extract files ending in .tar or .cpio.

Cpio options > file name or device name

Cpio option

< 文件名或者设备名 cpio -o 将文件拷贝打包成文件或者将文件输出到设备上 cpio -i 解包,将打包文件解压或将设备上的备份还原到系统 cpio -t 预览,查看文件内容或者输出到设备上的文件内容 cpio -v 显示打包过程中的文件名称 cpio -d 解包生成目录,在cpio还原时,自动建立的目录 cpio -c 一种比较新的存储方式 举例 将etc 目录备份 ~]# find /etc -print | cpio -ov >

Etc.cpio

Search the etc directory for file printout to the device to copy the file during the packaging process to output the file to the device to display the file name redirection name

Content preview

~] # cpio-tv

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

Database

Wechat

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

12
Report