当前位置:网站首页>Rhce8 Study Guide Chapter 6 archiving and compression
Rhce8 Study Guide Chapter 6 archiving and compression
2022-07-19 02:50:00 【Lao Duan studio】
6.1 file
In order to facilitate the transmission of files on the network , We need to package multiple files into one file ( file ). Common archiving commands include tar and cpio, Let's talk about tar Use ,cpio Please study by yourself .
tar The grammar is as follows .
tar cvf aa.tar file1 file2 file3
c Means to create an archive
v Show archived files when creating an archive , In order to simplify the output, you can not add v Options
f Used to specify archive files
This sentence means to file1 、file2、file3 Archive to aa.tar in .
The suffix is generally used for archived documents tar.
Prepare first , Copy several files to the current directory , The order is as follows .
[[email protected] ~]# cp /etc/hosts /etc/passwd /etc/services .
[[email protected] ~]# ls
anaconda-ks.cfg hosts initial-setup-ks.cfg passwd services
[[email protected] ~]#
And then put hosts, passwd, services Three files are filed into one file aa.tar, The order is as follows .
[[email protected] ~]# tar cf aa.tar hosts passwd services
[[email protected] ~]# ls
aa.tar anaconda-ks.cfg hosts initial-setup-ks.cfg passwd services
[[email protected] ~]#
The archive here is aa.tar, Check their size , The order is as follows .
[[email protected] ~]# ls -lh passwd services hosts aa.tar
-rw-r--r--. 1 root root 690K 8 month 10 23:33 aa.tar
-rw-r--r--. 1 root root 158 8 month 10 23:32 hosts
-rw-r--r--. 1 root root 2.6K 8 month 10 23:32 passwd
-rw-r--r--. 1 root root 677K 8 month 10 23:32 services
[[email protected] ~]#
You can see ,aa.tar The size of the file is larger than the sum of the three file sizes , Explain with tar Only archiving function , There's no compression .
From the above operations, we can see that when the archive file is created , The source file is still there , Namely the hosts、passwd、services Archive to aa.tar In the following , These three documents still exist . If you want to delete the source file after archiving , You can add –remove-files Options .
Delete aa.tar, Then archive again , The order is as follows .
[[email protected] ~]# rm -rf aa.tar
[[email protected] ~]# tar cf aa.tar hosts passwd services --remove-files
[[email protected] ~]# ls
aa.tar anaconda-ks.cfg initial-setup-ks.cfg
[[email protected] ~]#
Here you can see , Three files are archived to aa.tar Then it was deleted .
Check which files are in the archive , have access to t Options , The order is as follows .
[[email protected] ~]# tar tf aa.tar
hosts
passwd
services
[[email protected] ~]#
Want to add a file to the archive r Options , The order is as follows .
[[email protected] ~]# tar rf aa.tar anaconda-ks.cfg
[[email protected] ~]# tar tf aa.tar
hosts
passwd
services
anaconda-ks.cfg
[[email protected] ~]#
Here we have anaconda-ks.cfg write in aa.tar It's in .
Unpack the archived documents , The syntax of file resolution is as follows .
tar xvf aa.tar
here x It means to release the file
v Display the files that have been unpacked , To simplify the output ,v Options can be left blank
f Used to specify archive files
practice : hold aa.tar File release , The order is as follows .
[[email protected] ~]# tar xf aa.tar
[[email protected] ~]# ls
aa.tar anaconda-ks.cfg hosts initial-setup-ks.cfg passwd services
[[email protected] ~]#
You can see , The default is to unfurl to the current directory , If you want to unpack to the specified directory, you need to add -C Specify the directory , Now we have to put aa.tar Unsettle to /opt Directory , The order is as follows .
[[email protected] ~]# ls /opt/
[[email protected] ~]# tar xf aa.tar -C /opt
[[email protected] ~]# ls /opt
anaconda-ks.cfg hosts passwd services
[[email protected] ~]#
And then empty /opt The content in , The order is as follows .
[[email protected] ~]# rm -rf /opt/*
[[email protected] ~]# ls /opt
[[email protected] ~]#
Of course, you can only unlock aa.tar A file in , Just add the file to be de filed after the normal de filing command .
hold aa.tar Medium hosts Release the file and put it on /opt in , The order is as follows .
[[email protected] ~]# ls /opt
[[email protected] ~]#
[[email protected] ~]# tar xf aa.tar -C /opt hosts
[[email protected] ~]# ls /opt
hosts
[[email protected] ~]#
It should be noted that , here hosts To write in -C /opt Behind .
6.2 Compress
Speak in front of the tar Just archive , There's no compression . If you want to compress, there are special tools , Include gzip、bzip2、zip.
First create a test file , The order is as follows .
[[email protected] ~]# dd if=/dev/zero of=file bs=1M count=100
Recorded 100+0 Read in of
Recorded 100+0 Write
104857600 bytes (105 MB, 100 MiB) copied, 0.281021 s, 373 MB/s
[[email protected] ~]#
(1)if Is to read the content of where , Here is /dev/zero.
(2)of Is the file name of the composition .
(3)count Appoint zero Number of .
(4)bs Specify each zero Size , If no unit is specified, it defaults to B.
This means taking 100 Size is 1M Of /dev/zero Form a name called file The file of , this file The size of the should be 100M.
[[email protected] ~]# ls -lh file
-rw-r--r--. 1 root root 100M 8 month 10 23:48 file
[[email protected] ~]#
6.2.1 gzip Usage of
gzip Can be used as follows .
Compress :gzip file , The suffix of the compressed file is gz
decompression :gzip -d file.gz
Use gzip Yes file Compress , The order is as follows .
[[email protected] ~]# ls -lh file.gz
-rw-r--r--. 1 root root 100K 8 month 10 23:48 file.gz
[[email protected] ~]#
You can see ,file original 100M, Compressed into file.gz The size of 100K, Of course, because file The file is too simple, so the compression ratio is very high .
use gzip hold file.gz decompression , The order is as follows .
[[email protected] ~]# gzip -d file.gz
[[email protected] ~]#
In general ,tar and gzip Use together , Usage is as follows .
tar zcf aa.tar.gz file1 file2 file3
stay tar Add in options z Represents a call to gzip,z and c When used together, it means compression , The suffix is usually tar.gz. The meaning of this sentence is to put file1、file2、file3 Archive and compress to aa.tar.gz in .
practice : hold file Archive compressed to aa.tar.gz in , The order is as follows .
[[email protected] ~]# tar zcf aa.tar.gz file
[[email protected] ~]#
[[email protected] ~]# ls -lh aa.tar.gz file
-rw-r--r--. 1 root root 100M 8 month 10 23:48 file
-rw-r--r--. 1 root root 100K 8 month 11 00:22 aa.tar.gz
[[email protected] ~]#
decompression tar.gz Format file with tar zxf aa.tar.gz.
here z Represents a call to gzip, And x When used together, it means decompression .
[[email protected] ~]# rm -rf file
[[email protected] ~]# tar zxf aa.tar.gz
[[email protected] ~]#
6.2.2 bzip2 Usage of
bzip2 It is also a commonly used compression tool , Usage is as follows .
Compress : bzip2 file , The suffix of the compressed file is bz2
decompression : bzip2 -d file.bz2
Use bzip2 Yes file Compress , The order is as follows .
[[email protected] ~]# bzip2 file
[[email protected] ~]# ls -lh file.bz2
-rw-r--r--. 1 root root 113 8 month 10 23:48 file.bz2
[[email protected] ~]#
Here is the 100M Of file Can't compress 1K, Of course file The structure of is too simple, so the compression ratio is very high .
Use bzip2 unpack , The order is as follows .
[[email protected] ~]# bzip2 -d file.bz2
[[email protected] ~]#
In general ,tar and bzip2 Use together , Usage is as follows .
tar jcf aa.tar.bz2 file1 file2 file3
stay tar Add in options j Represents a call to bzip2,j and c When used together, it means compression , The suffix is usually tar.bz2. The meaning of this sentence is to put file1、file2、file3 Archive and compress to aa.tar.bz2 in .
[[email protected] ~]# tar jcf aa.tar.bz2 file
[[email protected] ~]# ls -lh aa.tar.bz2
-rw-r--r--. 1 root root 194 8 month 11 10:17 aa.tar.bz2
[[email protected] ~]#
decompression tar.bz2 Format file with tar jxf aa.tar.bz2.
here j Represents a call to bzip2, and x When used together, it means decompression .
[[email protected] ~]# rm -rf file
[[email protected] ~]# tar jxf aa.tar.bz2
[[email protected] ~]#
6.2.3 zip Usage of
zip Is a commonly used compression tool , stay Windows It's also often used in .zip Can be used as follows .
Compressed files : zip aa.zip file hold file Compress to aa.zip
Compressed Directory : zip -r bb.zip dir The directory dir Compress to bb.zip in
If you unzip zip Format of compressed files , Then use unzip, Usage is as follows .
unzip aa.zip
practice : hold file Compress to aa.zip in , The order is as follows .
[[email protected] ~]# zip aa.zip file
adding: file (deflated 100%)
[[email protected] ~]#
[[email protected] ~]# ls -lh file aa.zip
-rw-r--r--. 1 root root 100K 8 month 11 10:36 aa.zip
-rw-r--r--. 1 root root 100M 8 month 10 23:48 file
[[email protected] ~]#
decompression zip Format of compressed files , The order is as follows .
[[email protected] ~]# rm -rf file
[[email protected] ~]# unzip aa.zip
Archive: aa.zip
inflating: file
[[email protected] ~]#
Homework
There is a compressed file aa.tar.gz, Now the command to decompress him is :
a. tar xvf aa.tar.gz
b. tar jxf aa.tar.gz
c. tar zxf aa.tar.gz
d. gzip -d aa.tar.gzThere is a compressed file aa.tar.bz2, Now the command to decompress him is :
a. tar xvf aa.tar.gz
b. tar jxf aa.tar.gz
c. tar zxf aa.tar.gz
d. gzip -d aa.tar.gzThere is a compressed file figlet-2.2.4.tar.gz, Check which files are in it without unzipping , The order is ?
a. tar tf figlet-2.2.4.tar.gz
b. tar lf figlet-2.2.4.tar.gz
c. tar xf figlet-2.2.4.tar.gz
d. tar xf figlet-2.2.4.tar.gz
边栏推荐
猜你喜欢

Flask template injection

Zabbix6.0通过iDRAC,IMM2监控DELL,IBM服务器硬件

解决WIN10连接共享打印机出现0x00000709的错误

Circular statements and functions of shell scripts

The JMeter BeanShell implementation writes the parameterized data generated by the request to the file

Use JMeter to test services based on websocket protocol

Response assertion of JMeter interface test

摇摆摇摆~防火墙

Echo -e usage

Leetcode buckle classic question - 42 Connect rainwater
随机推荐
DNS domain name resolution
Uniapp wechat applet login (authorize wechat first and then mobile phone number) - (1)
Understanding of array and bubbling
expect免交互
RHCE-ansible-第一次作业
shell脚本之循环语句与函数
FTP service
The JMeter BeanShell implementation writes the parameterized data generated by the request to the file
Chapter 1 - multi agent system
使用gatekeeper限制kubernetes创建特定类型的资源
Leetcode 322: coin change - Dynamic Planning
RHCE学习指南 第5章 vim编辑器
MySQL backup and recovery
[unity development tips] unity mixer mixer controls global volume
使用Virtual IP+Keepalived配置高可用
Understand HTTP cache in 30 minutes
Bladex - a well-designed microservice architecture
ENSP静态路由实验
FTP服务
Shell script for, while loop statements, price guessing games