gzip压缩目录,linux下如何将文件压缩成gz文件
gzip压缩目录,linux下如何将文件压缩成gz文件详细介绍
本文目录一览: linux 中 用gzip 如何压缩目录?
1、连接上相应的linux主机,进入到等待输入shell指令的linux命令行状态下。
2、其次,在linux命令行中输入:gzip -c test.txt > test.gz。
3、最后,按下回车键执行shell指令,此时会看到test.txt成功被压缩到test.gz了。
linux下如何将文件压缩成gz文件
在Linux下,可以使用gzip工具将文件压缩成gz文件。下面是具体的步骤:
打开终端,进入要压缩的文件所在的目录。
运行以下命令进行压缩:
gzip 文件名其中,文件名为要压缩的文件名,可以是绝对路径或相对路径。
例如,要将文件test.txt压缩成test.txt.gz,可以运行以下命令:
gzip test.txt压缩完成后,原文件会被删除,只剩下压缩后的文件。如果不想删除原文件,可以使用以下命令进行压缩:
gzip -c 文件名 > 文件名.gz其中,-c选项表示将压缩后的数据输出到标准输出,>表示重定向输出到一个文件中。这样,压缩后的文件名为文件名.gz,原文件不会被删除。
例如,要将文件test.txt压缩成test.txt.gz,但不删除原文件,可以运行以下命令:
gzip -c test.txt > test.txt.gz压缩完成后,可以使用gunzip命令解压缩gz文件,例如:
gunzip 文件名.gz其中,文件名为要解压缩的gz文件名,解压缩后会生成一个同名的文件,去除.gz后缀。
Linux命令gzip -d怎么解压到指定路径
gzip是Linux系统中经常用来对文件进行压缩和解压缩的命令,通过此命令压缩得到的新文件,其扩展名通常标记为.gz。
请注意,gzip命令仅适用于压缩文件,无法压缩目录。即使指定了一个目录,它也只会压缩该目录下的所有文件。
gzip命令的基本格式如下:
[root@localhost ~]# gzip[选项]源文件
命令中的源文件,当进行压缩操作时,指的是普通文件;当进行解压缩操作时,指的是压缩文件。该命令常用的选项及含义如下:
-c 将压缩数据输出到标准输出中,并保留源文件。
-d 对压缩文件进行解压缩。
-r 递归压缩指定目录下以及子目录下的所有文件。
-v 对于每个压缩和解压缩的文件,显示相应的文件名和压缩比。
-l 对每一个压缩文件,显示以下字段:压缩文件的大小、未压缩文件的大小、压缩比、未压缩文件的名称。
-数字 用于指定压缩等级,-1 压缩等级最低,压缩比最差;-9压缩比最高。默认压缩比是 -6。
举例:基本压缩
gzip压缩命令非常简单,甚至不需要指定压缩之后的压缩包名,只需指定源文件名即可。
[root@localhost ~] #gzip install.log
#压缩instal.log 文件
[root#localhost ~]# ls
anaconda-ks.cfg install.log.gz install.log.syslog
#压缩文件生成,但是源文件也消失了
gzip
本身并没有解压到指定目录的参数。
如果是单文件压缩,可以用-c加输出重定向实现指定解压目录,如:
echo hello > xxxx #创建一个文件
mkdir dir1 #创建一个测试目录
gzip -c xxxx > ./dir1/xxxx.gz
rm xxxx
cd dir1
gzip -cd xxxx.gz > ../xxxx
ls -l xxxx
如果是用tar命令打包的文件压缩包,可以直接用tar命令-C功能指定目录,如:
tar cvf xxx.tar xxxx #文件打包
gzip xxx.tar #压缩
tar zxvf xxx.tar.gz -C ./dir1 #解压到指定目录
ls -l ./dir1/xxxx #查看结果
gzip怎么压缩和怎么解压缩文件到其他目录
解决:gzip -c test.txt > /root/test.gz,文件流重定向,解压也是,gunzip -c /root/test.gz > ./test.txt
经验:更常用的命令tar同样可以解压*.gz,参数为-c
附gzip帮助文件
GZIP(1) General Commands Manual GZIP(1)
NAME
gzip, gunzip, zcat - compress or expand files
SYNOPSIS
gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
zcat [ -fhLV ] [ name ... ]
OPTIONS
-a --ascii
Ascii text mode: convert end-of-lines using local conventions.
This option is supported only on some non-Unix systems. For
MSDOS, CR LF is converted to LF when compressing, and LF is con‐
verted to CR LF when decompressing.
-c --stdout --to-stdout
Write output on standard output; keep original files unchanged.
If there are several input files, the output consists of a
sequence of independently compressed members. To obtain better
compression, concatenate all input files before compressing
them.
-d --decompress --uncompress
Decompress.
-f --force
Force compression or decompression even if the file has multiple
links or the corresponding file already exists, or if the com‐
pressed data is read from or written to a terminal. If the input
data is not in a format recognized by gzip, and if the option
--stdout is also given, copy the input data without change to
the standard output: let zcat behave as cat. If -f is not
given, and when not running in the background, gzip prompts to
verify whether an existing file should be overwritten.
-h --help
Display a help screen and quit.
-l --list
For each compressed file, list the following fields:
compressed size: size of the compressed file
uncompressed size: size of the uncompressed file
ratio: compression ratio (0.0% if unknown)
uncompressed_name: name of the uncompressed file
The uncompressed size is given as -1 for files not in gzip for‐
mat, such as compressed .Z files. To get the uncompressed size
for such a file, you can use:
zcat file.Z | wc -c
In combination with the --verbose option, the following fields
are also displayed:
method: compression method
crc: the 32-bit CRC of the uncompressed data
date & time: time stamp for the uncompressed file
The compression methods currently supported are deflate, com‐
press, lzh (SCO compress -H) and pack. The crc is given as
ffffffff for a file not in gzip format.
With --name, the uncompressed name, date and time are those
stored within the compress file if present.
With --verbose, the size totals and compression ratio for all
files is also displayed, unless some sizes are unknown. With
--quiet, the title and totals lines are not displayed.
-L --license
Display the gzip license and quit.
-n --no-name
When compressing, do not save the original file name and time
stamp by default. (The original name is always saved if the name
had to be truncated.) When decompressing, do not restore the
original file name if present (remove only the gzip suffix from
the compressed file name) and do not restore the original time
stamp if present (copy it from the compressed file). This option
is the default when decompressing.
-N --name
When compressing, always save the original file name and time
stamp; this is the default. When decompressing, restore the
original file name and time stamp if present. This option is
useful on systems which have a limit on file name length or when
the time stamp has been lost after a file transfer.
-q --quiet
Suppress all warnings.
-r --recursive
Travel the directory structure recursively. If any of the file
names specified on the command line are directories, gzip will
descend into the directory and compress all the files it finds
there (or decompress them in the case of gunzip ).
-S .suf --suffix .suf
When compressing, use suffix .suf instead of .gz. Any non-empty
suffix can be given, but suffixes other than .z and .gz should
be avoided to avoid confusion when files are transferred to
other systems.
When decompressing, add .suf to the beginning of the list of
suffixes to try, when deriving an output file name from an input
file name.
pack(1).
-t --test
Test. Check the compressed file integrity.
-v --verbose
Verbose. Display the name and percentage reduction for each file
compressed or decompressed.
-V --version
Version. Display the version number and compilation options then
quit.
-# --fast --best
Regulate the speed of compression using the specified digit #,
where -1 or --fast indicates the fastest compression method
(less compression) and -9 or --best indicates the slowest com‐
pression method (best compression). The default compression
level is -6 (that is, biased towards high compression at expense
of speed).
linux压缩命令有什么 linux压缩命令介绍
1、gzip: 压缩后的文件后缀为.gz。用法:gzip+文件路径 ,压缩完成后会删除原文件。
2、bzip2:压缩后的文件后缀为.bz2.(比gzip有着更大压缩比的压缩工具,受用格式与其相似。)-k:压缩或者解压时可以保留原文件。
3、zip: 既归档又压缩的工具,可以压缩目录,以上三个不能,默认不删除原文件。
4、tar: 归档工具,也是很好的备份工具,后缀名为.tar.gz。
tar归档且压缩文件可以由gzip命令解压缩
tar后缀怎么解压1、打开软件,点击三角形箭头处。请点击输入图片描述点击压缩管理。请点击输入图片描述选择tar文件,点击解压。请点击输入图片描述选择解压存储位置后,点击确定。
2、tar文件解压方法:安装文件浏览器后打开,在主页面点击内部存储标签,按住需要解压的tar文件,选择压缩文件解压后保存的路径,点击“确定”即可。下载并安装文件浏览器,安装成功后返回桌面。通过手机桌面打开文件浏览器。
3、tar后缀的解压方法是将tar文件在浏览器上打开并保存。tar是一种在Linux系统中常见的文件压缩格式,解压文件需要通过文件浏览器或终端命令操作。因此,用户需要下载并安装文件浏览器,通过手机桌面打开文件浏览器。
4、tar.gz文件的解压方法如下:工具:惠普暗影精灵8Pro、windows1WinRAR21。右键压缩文件,选择WinRAR,再选择三个解压按钮中的一个。即可得到解压后的文件。
5、点击夸克网盘。打开夸克进入主页面,在页面中点击夸克网盘进入。点击压缩包。进入夸克网盘的主页面之后,在页面中点击压缩包进入。点击文件。进入压缩包的页面之后,在页面中可以看见tar文件,点击进入。点击解压。
6、然后命令中输入为:tar文件名.tar,然后直接回车即可,提示没有tar的命令。没有这个tar的命令是可以通过yum的方法来机型安装,直接输入yum-yinstalltar。
linux下将test目录进行归档,并用gzip进行压缩,这个具体命令是什么...1、linux中用gzip压缩目录步骤如下:打开linux客户端。点击连接linux按钮。输入用户名,主机ip地址。输入密码。连接成功,可以进行操作。
2、运行以下命令进行压缩:gzip文件名其中,文件名为要压缩的文件名,可以是绝对路径或相对路径。
3、bzip2:压缩后的文件后缀为.bz(比gzip有着更大压缩比的压缩工具,受用格式与其相似。)-k:压缩或者解压时可以保留原文件。zip:既归档又压缩的工具,可以压缩目录,以上三个不能,默认不删除原文件。
如何在Linux上使用tar命令解压和压缩文件1、#tar-xvfarchive_name.tar.gz上面这个解包命令将会将文档解开在当前目录下面。
2、压缩Desktop目录下所有的png文件为png.tar。解压png.tar到Desktop当前目录。
3、把目录打包为test.tar文件tar命令也可以打包多个文件或目录,只要用空格分开即可。
4、解压tar.bz2文件的例子:tar-jxv-ftest.tar.bz2-C/home/user/target下面说一下压缩文件,Linux上最常用的压缩格式一般是bzip2格式(常用bz2后缀)和gzip格式(常用gz后缀),因为它俩的压缩比比较高。
想在linux上用C实现gzip压缩与解压缩,有没有相关库函数可以调用
linux下只支持tar.gz和tgz等格式.zip它是读取不出来的!请您先用u盘把linux系统下的文件拷贝到windows系统下进行压缩和解压处理,处理完成放到u盘里带到linux系统中,不过我不觉得linux系统会支持zip
bz2格式...
建议您用虚拟机加载linux系统
命令: gzip语法:gzip [选项] 压缩(解压缩)的文件名
-c 将输出写到标准输出上,并保留原有文件。
-d 将压缩文件解压。
-l 对每个压缩文件,显示下列字段:
(1)压缩文件的大小
(2)未压缩文件的大小
(3)压缩比
未压缩文件的名字
-r 递归式地查找指定目录并压缩其中的所有文件或者是解压缩。
-t 测试,检查压缩文件是否完整。
-v 对每一个压缩和解压的文件,显示文件名和压缩比。
-num 用指定的数字num调整压缩的速度,-1或--fast表示最快压缩方法(低压缩比),-9或--best表示最慢压缩方法(高压缩比)。系统缺省值为6。
注:gzip不能压缩整个目录。可以使用tar先打包,再压缩
例如:
$ tar cf test.tar test/
$ gzip test.tar
或
$ tar czf test.tar.gz test/
文件压缩
将多个文件或目录合并成为一个特殊的文件
减小文件的体积 加快资源的传输 节省网络的带宽
windows: rar zip 其实支持很多类型的压缩 linux: zip tar.gz .... windows与linux互通 建议使用: zip
格式 压缩工具 .zip zip压缩工具 .gz gzip压缩工具,只能压缩文件,会删除原文件(通常配合tar使用) .bz2 bzip2压缩工具,只能压缩文件,会删除原文件(通常配合tar使用) .tar.gz 先使用tar命令归档打包,然后使用gzip压缩 .tar.bz2 先使用tar命令归档打包,然后使用bzip压缩
Linux gzip工具使用 1.gzip打包与压缩 ,仅对文件有效. gzip filename 打包 gzip -d filename.gz 解包 zcat filename.gz 查看包内文件的内容
linux本身没有gzip命令,需yum install gzip -y进行安装
gzip file #对文件进行压缩 zcat file.gz #查看gz压缩后的文件 gzip -d file.gz #解压gzip的压缩包
gzip CentOS-Vault.repo --> CentOS-Vault.repo.gz zcat CentOS-Vault.repo.gz --> 查看不想解压的压缩包
默认情况下没有zip和unzip工具,需要进行安装 yum install zip unzip -y
1.压缩文件为zip包 zip filename.zip filename unzip -l filename.zip #查看压缩包内容
2.压缩目录为zip包 zip -r dir.zip dir/
3.查看zip压缩包文件是否完整 zip -T filename.zip test of filename.zip OK
4.不解压压缩查看压缩包中的内容 unzip -l filename.zip unzip -t filename.zip #检测文件是 否都ok
5.解压zip文件包, 默认解压至当前目录 unzip filename.zip
6.解压zip内容至/opt目录 unzip filename.zip -d /opt/
tar是linux下最常用的压缩与解压缩, 支持文件和目录的压缩归档
c #创建新的归档文件 x #对归档文件解包 t #列出归档文件里的文件列表 f #指定包文件名,多参数f写最后 z #使用gzip压缩归档后的文件(.tar.gz) j #使用bzip2压缩归档后的文件(.tar.bz2) J #使用xz压缩归档后的文件(tar.xz) C #指定解压目录位置 X #排除多个文件(写入需要排除的文件名称) h #打包软链接 --exclude #在打包的时候写入需要排除文件或目录
cjf #打包tar.bz格式 * cJf #打包tar.xz格式 使用田少,不考虑 zxf #解压tar.gz格式 * jxf #解压tar.bz格式 *
常用 czf #打包tar.gz格式 ( ) tf #查看压缩包内容 xf #自动选择解压模式 ( )
将文件或目录进行打包压缩
tar czf test.tar.gz test/ test2/ #以gzip方式压缩 tar cjf test.tar.bz2 dir.txt dir/ #以bz2方式压缩
tar tf test.tar.gz tar tf test.tar.bz2 tar tf test.tar.xz
tar xf test.tar.gz tar xf test.tar.bz2 tar xf test.tar.xz tar xf root.tar.gz -C /tmp/ #解压至指定目录
find tmp/ -type f | xargs tar czf tmp.tar.gz tar czf tmp.tar.gz $(find /tmp/ -type f)
tar czf etc.tar.gz /etc/ --exclude=etc/services tar czf etc.tar.gz /etc/ --exclude=etc/passwd -exclude=etc/shadow
cat pc.txt etc/gshadow etc/gshadow- etc/passwd etc/passwd etc/shadow etc/shadow etc/security/opasswd etc/pam.d/passwd tar czXf pc.txt etc.tar.gz /etc/
yum install mariadb-server systemctl start mariadb mkdir /backup
tar cJf /backup/mysql.tar.xz /var/lib/mysql tar xf /backup/mysql.tar.xz -C /
cd /var/lib/mysql tar cJf /backup/mysql.tar.xz * tar tf /backup/mysql.tar.xz tar xf /backup/mysql.tar.xz C /var/lib/mysql
linux下备份一个目录下所有文件及目录,应该用什么命令?
1、bzip2 filename
//文件即会被压缩,并被保存为 filename.bz2。
2、gzip filename
//文件即会被压缩,并被保存为 filename.gz
3、tar 这个命令把大量的文件和目录打包成一个文件-c 创建一个新归档-f 当与-c 选项一起使用时,创建的tar 文件使用该选项指定的文件名;当与-x选项一起使用时,则解除该选项指定的归档-t 显示包括在tar 文件中的文件列表-v 显示文件的归档进度-x 从归档中抽取文件-z 使用gzip压缩tar 文件-j 使用bzip2压缩tar 文件
扩展资料:
要创建一个使用tar和bzip2来归档压缩的文件,使用-j选项: tar -cjvf filename.tbz file如果使用bunzip2 命令解压filename.tbz文件,则filename.tbz会被删除,以filename.tar代替。要扩展并解除归档bzip.tar文件,输入命令: tar -xjvf filename.tbz要创建一个用tar 和gzip归档并压缩的文件,使用-z选项: tar -czvf filename.tgz file如果使用gunzip 命令解压filename.tgz文件,则filename.tgz会被删除,以filename.tar代替。