当前位置:首页 » 文件管理 » gz怎么解压

gz怎么解压

发布时间: 2022-02-15 15:33:00

㈠ win7系统下怎样解压gz文件

你好,用7zip或者winrar都能直接解压。

linux 怎么解压.gz文件

gzip -d xxx.gz
或者: gunzip xxx.gz

㈢ Linux下如何解压文件夹下所有.gz的文件

需要准备的材料分别是:电脑、linux连接工具。

1、首先连接上linux主机,进入等待输入指令的linux命令行状态。

㈣ Linux解压.gz的命令是什么

  • 压缩命令:

    命令格式:tar -zxvf 压缩文件名.tar.gz。解压缩后的文件只能放在当前的目录。

  • 解压全部命令参考:

    tar –xvf file.tar 解压 tar包

    tar -xzvf file.tar.gz 解压tar.gz

    tar -xjvf file.tar.bz2 解压 tar.bz2

    tar –xZvf file.tar.Z 解压tar.Z

    unrar e file.rar 解压rar

    unzip file.zip 解压zip

㈤ linux怎样解压.gz文件

当在备份重要文件和通过网络发送大文件的时候,对文件进行压缩非常有用。请注意,压缩一个已经压缩过的文件会增加额外开销,因此你将会得到一个更大一些的文件。所以,请不要压缩已经压缩过的文件。在 GNU/Linux 中,有许多程序可以用来压缩和解压缩文件。在这篇教程中,我们仅学习其中两个应用程序。

在类 Unix 系统中,最常见的用来压缩文件的程序是:

  • gzip

  • bzip2

  • 1. 使用 gzip 程序来压缩和解压缩文件

    gzip是一个使用 Lempel-Ziv 编码(LZ77)算法来压缩和解压缩文件的实用工具。

    1.1 压缩文件

    如果要压缩一个名为ostechnix.txt的文件,使之成为 gzip 格式的压缩文件,那么只需运行如下命令:

  • $ gzip ostechnix.txt

  • 上面的命令运行结束之后,将会出现一个名为ostechnix.txt.gz的 gzip 格式压缩文件,代替了原始的ostechnix.txt文件。

    gzip命令还可以有其他用法。一个有趣的例子是,我们可以将一个特定命令的输出通过管道传递,然后作为gzip程序的输入来创建一个压缩文件。看下面的命令:

  • $ ls -l Downloads/ | gzip > ostechnix.txt.gz

  • 上面的命令将会创建一个 gzip 格式的压缩文件,文件的内容为Downloads目录的目录项。

    1.2 压缩文件并将输出写到新文件中(不覆盖原始文件)

    默认情况下,gzip程序会压缩给定文件,并以压缩文件替代原始文件。但是,你也可以保留原始文件,并将输出写到标准输出。比如,下面这个命令将会压缩ostechnix.txt文件,并将输出写入文件output.txt.gz。

  • $ gzip -c ostechnix.txt > output.txt.gz

  • 类似地,要解压缩一个gzip格式的压缩文件并指定输出文件的文件名,只需运行:

  • $ gzip -c -d output.txt.gz > ostechnix1.txt

  • 上面的命令将会解压缩output.txt.gz文件,并将输出写入到文件ostechnix1.txt中。在上面两个例子中,原始文件均不会被删除。

    1.3 解压缩文件

    如果要解压缩ostechnix.txt.gz文件,并以原始未压缩版本的文件来代替它,那么只需运行:

  • $ gzip -d ostechnix.txt.gz

  • 我们也可以使用gunzip程序来解压缩文件:

  • $ gunzip ostechnix.txt.gz

  • 1.4 在不解压缩的情况下查看压缩文件的内容

    如果你想在不解压缩的情况下,使用gzip程序查看压缩文件的内容,那么可以像下面这样使用-c选项:

  • $ gunzip -c ostechnix1.txt.gz

  • 或者,你也可以像下面这样使用zcat程序:

  • $ zcat ostechnix.txt.gz

  • 你也可以通过管道将输出传递给less命令,从而一页一页的来查看输出,就像下面这样:

  • $ gunzip -c ostechnix1.txt.gz | less

  • $ zcat ostechnix.txt.gz | less

  • 另外,zless程序也能够实现和上面的管道同样的功能。

  • $ zless ostechnix1.txt.gz

  • 1.5 使用 gzip 压缩文件并指定压缩级别

    gzip的另外一个显着优点是支持压缩级别。它支持下面给出的 3 个压缩级别:

  • 1– 最快 (最差)

  • 9– 最慢 (最好)

  • 6– 默认级别

  • 要压缩名为ostechnix.txt的文件,使之成为“最好”压缩级别的 gzip 压缩文件,可以运行:

  • $ gzip -9 ostechnix.txt

  • 1.6 连接多个压缩文件

    我们也可以把多个需要压缩的文件压缩到同一个文件中。如何实现呢?看下面这个例子。

  • $ gzip -c ostechnix1.txt > output.txt.gz

  • $ gzip -c ostechnix2.txt >> output.txt.gz

  • 上面的两个命令将会压缩文件ostechnix1.txt和ostechnix2.txt,并将输出保存到一个文件output.txt.gz中。

    你可以通过下面其中任何一个命令,在不解压缩的情况下,查看两个文件ostechnix1.txt和ostechnix2.txt的内容:

  • $ gunzip -c output.txt.gz

  • $ gunzip -c output.txt

  • $ zcat output.txt.gz

  • $ zcat output.txt

  • 如果你想了解关于gzip的更多细节,请参阅它的 man 手册。

  • $ man gzip

  • 2. 使用 bzip2 程序来压缩和解压缩文件

    bzip2和gzip非常类似,但是bzip2使用的是 Burrows-Wheeler 块排序压缩算法,并使用哈夫曼(Huffman)编码。使用bzip2压缩的文件以 “.bz2” 扩展结尾。

    正如我上面所说的,bzip2的用法和gzip几乎完全相同。只需在上面的例子中将gzip换成bzip2,将gunzip换成bunzip2,将zcat换成bzcat即可。

    要使用bzip2压缩一个文件,并以压缩后的文件取而代之,只需运行:

  • $ bzip2 ostechnix.txt

  • 如果你不想替换原始文件,那么可以使用-c选项,并把输出写入到新文件中。

  • $ bzip2 -c ostechnix.txt > output.txt.bz2

  • 如果要解压缩文件,则运行:

  • $ bzip2 -d ostechnix.txt.bz2

  • 或者,

  • $ bunzip2 ostechnix.txt.bz2

  • 如果要在不解压缩的情况下查看一个压缩文件的内容,则运行:

  • $ bunzip2 -c ostechnix.txt.bz2

  • 或者,

  • $ bzcat ostechnix.txt.bz2

  • 如果你想了解关于bzip2的更多细节,请参阅它的 man 手册。

  • $ man bzip2

  • 总结

    在这篇教程中,我们学习了gzip和bzip2程序是什么,并通过 GNU/Linux 下的一些例子学习了如何使用它们来压缩和解压缩文件。接下来,我们将要学习如何在 Linux 中将文件和目录归档。

    干杯!

㈥ 如何解压缩.gz文件

public static void makeZip(List<File> fileList,String zipPath,boolean isDelete) {
byte[] buf = new byte[1024];
try {
// Create the ZIP file
File zipFile = new File(zipPath);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
// Compress the files
for (int i = 0; i < fileList.size(); i++) {
FileInputStream in = new FileInputStream(fileList.get(i));
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(fileList.get(i).getName()));
// Transfer bytes from the file to the ZIP file
int len;
while ( (len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
System.out.println("压缩完成.");

//把旧的文件删除
if(isDelete == true){
for (int i = 0; i < fileList.size(); i++) {
File oldFile = fileList.get(i);
oldFile.delete();
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
File in1=new File("D:\\a.txt");
File in2=new File("D:\\b.txt");
File[] file=new File[]{in1,in2};
File zip=new File("D:\\ab.zip");
IDMZip mgr=new IDMZip();
mgr.ZipFiles(file, zip);
}

这个方法不管你是在windows下还是在linux下,都能正常执行。
追问
谢谢,但是我是要解压这样20140718_185819.data.tar.gz 不是zip的

回答
你可以试试。还有这个方法。都是我项目里曾经用到过的。都是可用的。
public static List unZip(String path) throws FileNotFoundException,
IOException {
path = path.replaceAll("\\\\","/");
String zipPath = path.substring(0,path.lastIndexOf("/")+1);
List xmlFileNameList = new ArrayList();
byte[] data = new byte[1024*2];
FileInputStream fis = new FileInputStream(path);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry entry = null;
while((entry = zis.getNextEntry())!= null){
if(entry.isDirectory()){
File file = new File(zipPath+entry.getName());
file.mkdirs();
continue;
}

㈦ *.gz是什么文件如何解压

gzip格式压缩文件
解压命令:gzip -d filename

㈧ 如何解压.tar.gz gzip gz 类型文档

java解压缩.gz .zip .tar.gz等格式的压缩包方法总结
1、.gz文件是linux下常见的压缩格式。使用 java.util.zip.GZIPInputStream即可,压缩是 java.util.zip.GZIPOutputStream

1 public static void unGzipFile(String sourcedir) {
2 String ouputfile = "";
3 try {
4 //建立gzip压缩文件输入流
5 FileInputStream fin = new FileInputStream(sourcedir);
6 //建立gzip解压工作流
7 GZIPInputStream gzin = new GZIPInputStream(fin);
8 //建立解压文件输出流
9 ouputfile = sourcedir.substring(0,sourcedir.lastIndexOf('.'));
10 ouputfile = ouputfile.substring(0,ouputfile.lastIndexOf('.'));
11 FileOutputStream fout = new FileOutputStream(ouputfile);
12
13 int num;
14 byte[] buf=new byte[1024];
15
16 while ((num = gzin.read(buf,0,buf.length)) != -1)
17 {
18 fout.write(buf,0,num);
19 }
20
21 gzin.close();
22 fout.close();
23 fin.close();
24 } catch (Exception ex){
25 System.err.println(ex.toString());
26 }
27 return;
28 }

2、zip文件,使用java.util.zip.ZipEntry 和 java.util.zip.ZipFile

1 /**
2 * 解压缩zipFile
3 * @param file 要解压的zip文件对象
4 * @param outputDir 要解压到某个指定的目录下
5 * @throws IOException
6 */
7 public static void unZip(File file,String outputDir) throws IOException {
8 ZipFile zipFile = null;
9
10 try {
11 Charset CP866 = Charset.forName("CP866"); //specifying alternative (non UTF-8) charset
12 //ZipFile zipFile = new ZipFile(zipArchive, CP866);
13 zipFile = new ZipFile(file, CP866);
14 createDirectory(outputDir,null);//创建输出目录
15
16 Enumeration<?> enums = zipFile.entries();
17 while(enums.hasMoreElements()){
18
19 ZipEntry entry = (ZipEntry) enums.nextElement();
20 System.out.println("解压." + entry.getName());
21
22 if(entry.isDirectory()){//是目录
23 createDirectory(outputDir,entry.getName());//创建空目录
24 }else{//是文件
25 File tmpFile = new File(outputDir + "/" + entry.getName());
26 createDirectory(tmpFile.getParent() + "/",null);//创建输出目录
27
28 InputStream in = null;
29 OutputStream out = null;
30 try{
31 in = zipFile.getInputStream(entry);;
32 out = new FileOutputStream(tmpFile);
33 int length = 0;
34
35 byte[] b = new byte[2048];
36 while((length = in.read(b)) != -1){
37 out.write(b, 0, length);
38 }
39
40 }catch(IOException ex){
41 throw ex;
42 }finally{
43 if(in!=null)
44 in.close();
45 if(out!=null)
46 out.close();
47 }
48 }
49 }
50
51 } catch (IOException e) {
52 throw new IOException("解压缩文件出现异常",e);
53 } finally{
54 try{
55 if(zipFile != null){
56 zipFile.close();
57 }
58 }catch(IOException ex){
59 throw new IOException("关闭zipFile出现异常",ex);
60 }
61 }
62 }
63
64 /**
65 * 构建目录
66 * @param outputDir
67 * @param subDir
68 */
69 public static void createDirectory(String outputDir,String subDir){
70 File file = new File(outputDir);
71 if(!(subDir == null || subDir.trim().equals(""))){//子目录不为空
72 file = new File(outputDir + "/" + subDir);
73 }
74 if(!file.exists()){
75 if(!file.getParentFile().exists())
76 file.getParentFile().mkdirs();
77 file.mkdirs();
78 }
79 }

3、.tar.gz文件可以看做先用tar打包,再使用gz进行压缩。
使用org.apache.tools.tar.TarEntry; org.apache.tools.tar.TarInputStream 和 org.apache.tools.tar.TarOutputStream

1 //------------------------------------------------------------------------------------------------------
2 /**
3 * 解压tar.gz 文件
4 * @param file 要解压的tar.gz文件对象
5 * @param outputDir 要解压到某个指定的目录下
6 * @throws IOException
7 */
8 public static void unTarGz(File file,String outputDir) throws IOException{
9 TarInputStream tarIn = null;
10 try{
11 tarIn = new TarInputStream(new GZIPInputStream(
12 new BufferedInputStream(new FileInputStream(file))),
13 1024 * 2);
14
15 createDirectory(outputDir,null);//创建输出目录
16
17 TarEntry entry = null;
18 while( (entry = tarIn.getNextEntry()) != null ){
19
20 if(entry.isDirectory()){//是目录
21 entry.getName();
22 createDirectory(outputDir,entry.getName());//创建空目录
23 }else{//是文件
24 File tmpFile = new File(outputDir + "/" + entry.getName());
25 createDirectory(tmpFile.getParent() + "/",null);//创建输出目录
26 OutputStream out = null;
27 try{
28 out = new FileOutputStream(tmpFile);
29 int length = 0;
30
31 byte[] b = new byte[2048];
32
33 while((length = tarIn.read(b)) != -1){
34 out.write(b, 0, length);
35 }
36
37 }catch(IOException ex){
38 throw ex;
39 }finally{
40
41 if(out!=null)
42 out.close();
43 }
44 }
45 }
46 }catch(IOException ex){
47 throw new IOException("解压归档文件出现异常",ex);
48 } finally{
49 try{
50 if(tarIn != null){
51 tarIn.close();
52 }
53 }catch(IOException ex){
54 throw new IOException("关闭tarFile出现异常",ex);
55 }
56 }
57 }

使用到的包头有:

1 import java.io.BufferedInputStream;
2 import java.io.File;
3 import java.io.FileInputStream;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.OutputStream;
8
9 import java.nio.charset.Charset;
10 import java.util.Enumeration;
11 import java.util.zip.GZIPInputStream;
12 import java.util.zip.ZipEntry;
13 import java.util.zip.ZipFile;
14
15 import org.apache.tools.tar.TarEntry;
16 import org.apache.tools.tar.TarInputStream;
17 import org.apache.tools.tar.TarOutputStream;

㈨ 如何解压gz文件

当在备份重要文件和通过网络发送大文件的时候,对文件进行压缩非常有用。请注意,压缩一个已经压缩过的文件会增加额外开销,因此你将会得到一个更大一些的文件。所以,请不要压缩已经压缩过的文件。在 GNU/Linux 中,有许多程序可以用来压缩和解压缩文件。在这篇教程中,我们仅学习其中两个应用程序。

在类 Unix 系统中,最常见的用来压缩文件的程序是:

  • gzip

  • bzip2

  • 1. 使用 gzip 程序来压缩和解压缩文件

    gzip是一个使用 Lempel-Ziv 编码(LZ77)算法来压缩和解压缩文件的实用工具。

    1.1 压缩文件

    如果要压缩一个名为ostechnix.txt的文件,使之成为 gzip 格式的压缩文件,那么只需运行如下命令:

  • $ gzip ostechnix.txt

  • 上面的命令运行结束之后,将会出现一个名为ostechnix.txt.gz的 gzip 格式压缩文件,代替了原始的ostechnix.txt文件。

    gzip命令还可以有其他用法。一个有趣的例子是,我们可以将一个特定命令的输出通过管道传递,然后作为gzip程序的输入来创建一个压缩文件。看下面的命令:

  • $ ls -l Downloads/ | gzip > ostechnix.txt.gz

  • 上面的命令将会创建一个 gzip 格式的压缩文件,文件的内容为Downloads目录的目录项。

    1.2 压缩文件并将输出写到新文件中(不覆盖原始文件)

    默认情况下,gzip程序会压缩给定文件,并以压缩文件替代原始文件。但是,你也可以保留原始文件,并将输出写到标准输出。比如,下面这个命令将会压缩ostechnix.txt文件,并将输出写入文件output.txt.gz。

  • $ gzip -c ostechnix.txt > output.txt.gz

  • 类似地,要解压缩一个gzip格式的压缩文件并指定输出文件的文件名,只需运行:

  • $ gzip -c -d output.txt.gz > ostechnix1.txt

  • 上面的命令将会解压缩output.txt.gz文件,并将输出写入到文件ostechnix1.txt中。在上面两个例子中,原始文件均不会被删除。

    1.3 解压缩文件

    如果要解压缩ostechnix.txt.gz文件,并以原始未压缩版本的文件来代替它,那么只需运行:

  • $ gzip -d ostechnix.txt.gz

  • 我们也可以使用gunzip程序来解压缩文件:

  • $ gunzip ostechnix.txt.gz

  • 1.4 在不解压缩的情况下查看压缩文件的内容

    如果你想在不解压缩的情况下,使用gzip程序查看压缩文件的内容,那么可以像下面这样使用-c选项:

  • $ gunzip -c ostechnix1.txt.gz

  • 或者,你也可以像下面这样使用zcat程序:

  • $ zcat ostechnix.txt.gz

  • 你也可以通过管道将输出传递给less命令,从而一页一页的来查看输出,就像下面这样:

  • $ gunzip -c ostechnix1.txt.gz | less

  • $ zcat ostechnix.txt.gz | less

  • 另外,zless程序也能够实现和上面的管道同样的功能。

  • $ zless ostechnix1.txt.gz

  • 1.5 使用 gzip 压缩文件并指定压缩级别

    gzip的另外一个显着优点是支持压缩级别。它支持下面给出的 3 个压缩级别:

  • 1– 最快 (最差)

  • 9– 最慢 (最好)

  • 6– 默认级别

  • 要压缩名为ostechnix.txt的文件,使之成为“最好”压缩级别的 gzip 压缩文件,可以运行:

  • $ gzip -9 ostechnix.txt

  • 1.6 连接多个压缩文件

    我们也可以把多个需要压缩的文件压缩到同一个文件中。如何实现呢?看下面这个例子。

  • $ gzip -c ostechnix1.txt > output.txt.gz

  • $ gzip -c ostechnix2.txt >> output.txt.gz

  • 上面的两个命令将会压缩文件ostechnix1.txt和ostechnix2.txt,并将输出保存到一个文件output.txt.gz中。

    你可以通过下面其中任何一个命令,在不解压缩的情况下,查看两个文件ostechnix1.txt和ostechnix2.txt的内容:

  • $ gunzip -c output.txt.gz

  • $ gunzip -c output.txt

  • $ zcat output.txt.gz

  • $ zcat output.txt

  • 如果你想了解关于gzip的更多细节,请参阅它的 man 手册。

  • $ man gzip

  • 2. 使用 bzip2 程序来压缩和解压缩文件

    bzip2和gzip非常类似,但是bzip2使用的是 Burrows-Wheeler 块排序压缩算法,并使用哈夫曼(Huffman)编码。使用bzip2压缩的文件以 “.bz2” 扩展结尾。

    正如我上面所说的,bzip2的用法和gzip几乎完全相同。只需在上面的例子中将gzip换成bzip2,将gunzip换成bunzip2,将zcat换成bzcat即可。

    要使用bzip2压缩一个文件,并以压缩后的文件取而代之,只需运行:

  • $ bzip2 ostechnix.txt

  • 如果你不想替换原始文件,那么可以使用-c选项,并把输出写入到新文件中。

  • $ bzip2 -c ostechnix.txt > output.txt.bz2

  • 如果要解压缩文件,则运行:

  • $ bzip2 -d ostechnix.txt.bz2

  • 或者,

  • $ bunzip2 ostechnix.txt.bz2

  • 如果要在不解压缩的情况下查看一个压缩文件的内容,则运行:

  • $ bunzip2 -c ostechnix.txt.bz2

  • 或者,

  • $ bzcat ostechnix.txt.bz2

  • 如果你想了解关于bzip2的更多细节,请参阅它的 man 手册。

  • $ man bzip2

  • 总结

    在这篇教程中,我们学习了gzip和bzip2程序是什么,并通过 GNU/Linux 下的一些例子学习了如何使用它们来压缩和解压缩文件。接下来,我们将要学习如何在 Linux 中将文件和目录归档。

    干杯!

㈩ linux怎样解压gz文件

单纯的.gz文件解压,这种文件不可以使用tar命令解压,需要用gunzip解压,使用命令gzip

解压:gzip -b pythontab.gz

但是注意:gzip貌似不能够设置解压到指定目录,只能解压到当前目录。

解压单纯的.gz文件方法二:

使用zcat命令,然后把标准输出保存到文件即可。

热点内容
秦遥控驾驶是哪个配置 发布:2024-10-26 00:25:48 浏览:847
神雕侠侣服务器连接超时怎么回事 发布:2024-10-26 00:25:28 浏览:380
11系统如何安装安卓应用 发布:2024-10-26 00:22:40 浏览:712
rar解压缩破解版 发布:2024-10-26 00:12:43 浏览:380
javarestfulapi开发 发布:2024-10-26 00:04:04 浏览:443
服务器设置业务口ip 发布:2024-10-25 23:46:12 浏览:69
手机游戏解压缩怎么用 发布:2024-10-25 23:45:57 浏览:255
存储过程性能 发布:2024-10-25 23:35:39 浏览:111
同一个ip是不是同一个服务器 发布:2024-10-25 23:33:15 浏览:518
为啥c语言要编译器啊 发布:2024-10-25 23:32:38 浏览:218