當前位置:首頁 » 文件管理 » 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命令行狀態下。

熱點內容
SQL寫序列 發布:2024-09-20 06:02:29 瀏覽:963
裝緩存下載 發布:2024-09-20 05:42:36 瀏覽:72
gon引擎自動回收腳本 發布:2024-09-20 05:39:39 瀏覽:246
好醫生連鎖店密碼多少 發布:2024-09-20 05:09:38 瀏覽:15
魔獸腳本代理 發布:2024-09-20 05:09:35 瀏覽:99
python登陸網頁 發布:2024-09-20 05:08:39 瀏覽:758
安卓qq飛車如何轉蘋果 發布:2024-09-20 04:54:30 瀏覽:178
存儲過程中in什麼意思 發布:2024-09-20 04:24:20 瀏覽:315
php顯示數據 發布:2024-09-20 03:48:38 瀏覽:501
源碼安裝軟體 發布:2024-09-20 03:44:31 瀏覽:354