当前位置:首页 » 文件管理 » gzip解压命令

gzip解压命令

发布时间: 2022-01-09 08:16:56

linux压缩的命令怎么用

用法如下:

gzip,压缩文件名:zip或gz,解压命令:unzip

bzip2,压缩文件名:bz,解压命令;bzip2 -d

上面两个是最常用的压缩方式,一般在linux下可以通过tar命令实现打包和压缩(或解压)。例如:

tar -zcvf file file.tar.gz打包并压缩成gzip格式,其中-c命令是创建tar包,-z参数是指定压缩成gzip格式;

tar -zxvf file.tar.gz解包命令,其中-x是解包命令,-z指定解压缩格式是gzip

tar -jcvf file file.tar.bz2 打包并压缩成bzip2格式,其中-c是创建tar包,-j参数指定压缩成bzip2格式;

tar -jxvf file.tar.gz解包命令,其中-x是解包命令,-j指定解压缩格式是bzip2

Ⅱ 请教怎么解压.tar.gz .gzip .gz 类型文档

我在网上找到些代码,可以实现上传并解压tar.gz格式文档到服务器, 其它格式比如gzip, gz无法上传解压成功(即服务器上传目录没文件). PHP code $zipFile = $_FILES["file"]["tmp_name"]; $zp = @fopen($zipFile, "r"); $fp=popen('tar xzf - --overwrite --directory='.$uploadDir.'/','w'); while(!@feof($zp)) { $string = @fread($zp, 4096); @fwrite($fp, $string, strlen($string)); } @fclose($zp); @pclose($fp); 我在网上看到听说使用pharData 类可以实现, 但我看不懂. ------解决方案--------------------------------------------------------刚好 自己试看看是不是可以支持你上面的那几个格式 $zip = new ZipArchive; if ($zip->open('test.gzip') === TRUE) { $zip->extractTo('./test/'); $zip->close(); ------解决方案--------------------------------------------------------实在找不到,判断下文件后缀,然后直接用system发送系统命令来解压吧。

Ⅲ 如何查看gzip 命令解压后的文件

权限不够,做这个操作必须是-user student 用户或超级用户root,其他用户都会报错。

Ⅳ linux下的gzip命令如何运用

linux下的gzip命令运用方法如下:

1、打开linux客户端。


Ⅳ 如何解压.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;

Ⅵ gzip怎么压缩和怎么解压缩文件到其他目录

  1. 解决:gzip -c test.txt > /root/test.gz,文件流重定向,解压也是,gunzip -c /root/test.gz > ./test.txt

  2. 经验:更常用的命令tar同样可以解压*.gz,参数为-c

  3. 附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, 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 ( 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 rection 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解压.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

Ⅷ 求后缀gzip的文件怎么打开或解压。

你可以下载一个7-zip 这是一个解压文件~~!下完后,在点文件文件时,他会出现。点open....在点击蹦出来的文件,就行了!

Ⅸ linux解压zip文件的命令

linux怎么解压zip包,操作方法如下。

1、首先在电脑中,连接到linux远程主机,并进入zip文件所在目录,如下图所示。

Ⅹ linux把文件压缩成.tar.gz的命令

1、连接上相应的linux主机,进入到等待输入shell指令的linux命令行状态下。

热点内容
上传文件文件夹找不到 发布:2024-09-20 00:26:32 浏览:914
承台箍筋加密区 发布:2024-09-20 00:26:31 浏览:227
笔记本什么配置能流畅运行cf 发布:2024-09-20 00:14:19 浏览:951
实测华为编译器 发布:2024-09-19 23:50:52 浏览:821
linux汇总 发布:2024-09-19 23:46:39 浏览:452
阿里云服务器环境搭建教程 发布:2024-09-19 23:21:58 浏览:837
黄色文件夹图标 发布:2024-09-19 23:19:22 浏览:684
mysql数据库导出导入 发布:2024-09-19 23:00:47 浏览:183
lua脚本精灵 发布:2024-09-19 23:00:41 浏览:659
任务栏文件夹图标 发布:2024-09-19 22:54:25 浏览:101