2009-12-07 20:01:59 +0000 2009-12-07 20:01:59 +0000
89
89
Advertisement

Come posso decomprimere un .tar.gz in un solo passo (usando 7-Zip)?

Advertisement

Sto usando 7-Zip su Windows XP e ogni volta che scarico un file .tar.gz mi ci vogliono due passaggi per estrarre completamente il/i file.

  1. Clicco con il tasto destro sul file example.tar.gz e scelgo 7-Zip –> Estrai qui dal menu contestuale.
  2. Poi prendo il file example.tar risultante e clicco di nuovo con il tasto destro e scelgo 7-Zip –> Estrai qui dal menu contestuale.

C'è un modo attraverso il menu contestuale per fare questo in un solo passo?

Advertisement
Advertisement

Risposte (7)

49
49
49
2009-12-07 20:07:52 +0000

Non proprio. Un file .tar.gz o .tgz è in realtà due formati: .tar è l'archivio, e .gz è la compressione. Quindi il primo passo decomprime, e il secondo passo estrae l'archivio.

Per fare tutto in un solo passo, hai bisogno del programma tar. Cygwin include questo.

tar xzvf foobaz.tar.gz

; x = eXtract 
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename

Puoi anche farlo “in un solo passo” aprendo il file nella GUI di 7-zip: Apri il file .tar.gz, fai doppio clic sul file .tar incluso, poi estrai quei file nella posizione che preferisci.

C'è un lungo thread qui di gente che chiede/vota per una gestione one-step dei file tgz e bz2. La mancanza di azione fino ad ora indica che non succederà fino a quando qualcuno non farà un passo avanti e contribuirà in modo significativo (codice, soldi, qualcosa).

26
26
26
2013-02-05 02:07:01 +0000

Vecchia domanda, ma ci stavo lottando oggi, quindi ecco la mia 2c. Lo strumento da riga di comando 7zip “7z.exe” (ho installato la v9.22) può scrivere su stdout e leggere da stdin, quindi puoi fare a meno del file tar intermedio usando una pipe:

7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"

dove:

x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory

Vedi il file di aiuto (7-zip.chm) nella directory di installazione per maggiori informazioni sui comandi della linea di comando e sugli switch.

Puoi creare una voce di menu contestuale per i file .tar.gz/.tgz che richiama il comando di cui sopra usando regedit o uno strumento di terze parti come stexbar .

10
Advertisement
10
10
2018-01-07 20:23:00 +0000
Advertisement

A partire da 7-zip 9.04 c'è un'opzione a riga di comando per fare l'estrazione combinata senza usare la memorizzazione intermedia per il semplice file .tar:

7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar

-tgzip è necessaria se il file di input si chiama .tgz invece di .tar.gz.

4
4
4
2011-11-26 05:34:01 +0000

Stai usando Windows XP, quindi dovresti avere Windows Scripting Host installato di default. Detto questo, ecco uno script WSH JScript per fare quello che ti serve. Basta copiare il codice in un file di nome xtract.bat o qualcosa del genere (può essere qualsiasi cosa purché abbia l'estensione .bat), ed eseguirlo:

xtract.bat example.tar.gz

Di default, lo script controllerà la cartella dello script, così come la variabile d'ambiente PATH del vostro sistema per 7z.exe. Se vuoi cambiare il modo in cui cerca le cose, puoi cambiare la variabile SevenZipExe all'inizio dello script con qualsiasi nome tu voglia per l'eseguibile. (Per esempio, 7za.exe o 7z-real.exe) Puoi anche impostare una directory di default per l'eseguibile cambiando SevenZipDir. Quindi, se 7z.exe è a C:\Windows\system32z.exe, metterai:

var SevenZipDir = "C:\Windows\system32";

Comunque, ecco lo script:

@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]

/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName( __file__ );
var PWD = WSH.CurrentDirectory;

/* Prototypes */
(function(obj) {
    obj.has = function object_has(key) {
        return defined(this[key]);
    };
    return obj;
})(this.Object.prototype);

(function(str) {
    str.trim = function str_trim() {
        return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    };
})(this.String.prototype);

(function(arr) {
    arr.contains = function arr_contains(needle) {
        for (var i in this) {
            if (this[i] == needle) {
                return true;
            }
        }
        return false;
    }
})(this.Array.prototype);

/* Utility functions */
function defined(obj)
{
    return typeof(obj) != "undefined";
}

function emptyStr(obj)
{
    return !(defined(obj) && String(obj).length);
}

/* WSH-specific Utility Functions */
function echo()
{
    if(!arguments.length) return;
    var msg = "";
    for (var n = 0; n < arguments.length; n++) {
        msg += arguments[n];
        msg += " ";
    }
    if(!emptyStr(msg))
        WScript.Echo(msg);
}

function fatal(msg)
{
    echo("Fatal Error:", msg);
    WScript.Quit(1);
}

function findExecutable()
{
    // This function searches the directories in;
    // the PATH array for the specified file name;
    var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
    var exec = SevenZipExe;
    var strTestPath = FSO.BuildPath(dirTest, exec);
    if (FSO.FileExists(strTestPath))
        return FSO.GetAbsolutePathName(strTestPath);

    var arrPath = String(
            dirTest + ";" + 
            WSH.ExpandEnvironmentStrings("%PATH%")
        ).split(";");

    for(var i in arrPath) {
        // Skip empty directory values, caused by the PATH;
        // variable being terminated with a semicolon;
        if (arrPath[i] == "")
            continue;

        // Build a fully qualified path of the file to test for;
        strTestPath = FSO.BuildPath(arrPath[i], exec);

        // Check if (that file exists;
        if (FSO.FileExists(strTestPath))
            return FSO.GetAbsolutePathName(strTestPath);
    }
    return "";
}

function readall(oExec)
{
    if (!oExec.StdOut.AtEndOfStream)
      return oExec.StdOut.ReadAll();

    if (!oExec.StdErr.AtEndOfStream)
      return oExec.StdErr.ReadAll();

    return -1;
}

function xtract(exec, archive)
{
    var splitExt = /^(.+)\.(\w+)$/;
    var strTmp = FSO.GetFileName(archive);
    WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
    while(true) {
        var pathParts = splitExt.exec(strTmp);
        if(!pathParts) {
            echo("No extension detected for", strTmp + ".", "Skipping..");
            break;
        }

        var ext = pathParts[2].toLowerCase();
        if(!ArchiveExts.contains(ext)) {
            echo("Extension", ext, "not recognized. Skipping.");
            break;
        }

        echo("Extracting", strTmp + "..");
        var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
        var allInput = "";
        var tryCount = 0;

        while (true)
        {
            var input = readall(oExec);
            if (-1 == input) {
                if (tryCount++ > 10 && oExec.Status == 1)
                    break;
                WScript.Sleep(100);
             } else {
                  allInput += input;
                  tryCount = 0;
            }
        }

        if(oExec. ExitCode!= 0) {
            echo("Non-zero return code detected.");
            break;
        }

        WScript.Echo(allInput);

        strTmp = pathParts[1];
        if(!FSO.FileExists(strTmp))
            break;
    }
    WSH.CurrentDirectory = PWD;
}

function printUsage()
{
    echo("Usage:\r\n", __file__ , "archive1 [archive2] ...");
    WScript.Quit(0);
}

function main(args)
{
    var exe = findExecutable();
    if(emptyStr(exe))
        fatal("Could not find 7zip executable.");

    if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
        printUsage();

    for (var i = 0; i < args.length; i++) {
        var archive = FSO.GetAbsolutePathName(args(i));
        if(!FSO.FileExists(archive)) {
            echo("File", archive, "does not exist. Skipping..");
            continue;
        }
        xtract(exe, archive);
    }
    echo("\r\nDone.");
}

main(WScript.Arguments.Unnamed);
2
Advertisement
2
2
2016-10-29 18:37:40 +0000
Advertisement

Come potete vedere 7-Zip non è molto bravo in questo. La gente ha [ chiesto l'operazione atomica (http://sourceforge.net/p/sevenzip/discussion/45797/thread/5eb1b8d5)tarball dal 2009. Qui c'è un piccolo programma (490 KB) in Go che può farlo, l'ho compilato per te.

package main
import (
  "archive/tar"
  "compress/gzip"
  "flag"
  "fmt"
  "io"
  "os"
  "strings"
 )

func main() {
  flag.Parse() // get the arguments from command line
  sourcefile := flag.Arg(0)
  if sourcefile == "" {
    fmt.Println("Usage : go-untar sourcefile.tar.gz")
    os.Exit(1)
  }
  file, err := os.Open(sourcefile)
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
  defer file.Close()
  var fileReader io.ReadCloser = file
  // just in case we are reading a tar.gz file,
  // add a filter to handle gzipped file
  if strings.HasSuffix(sourcefile, ".gz") {
    if fileReader, err = gzip.NewReader(file); err != nil {
      fmt.Println(err)
      os.Exit(1)
    }
    defer fileReader.Close()
  }
  tarBallReader := tar.NewReader(fileReader)
  // Extracting tarred files
  for {
    header, err := tarBallReader.Next()
    if err != nil {
      if err == io.EOF {
        break
      }
      fmt.Println(err)
      os.Exit(1)
    }
    // get the individual filename and extract to the current directory
    filename := header.Name
    switch header.Typeflag {
    case tar.TypeDir:
      // handle directory
      fmt.Println("Creating directory :", filename)
      // or use 0755 if you prefer
      err = os.MkdirAll(filename, os.FileMode(header.Mode))
      if err != nil {
        fmt.Println(err)
        os.Exit(1)
      }
    case tar.TypeReg:
      // handle normal file
      fmt.Println("Untarring :", filename)
      writer, err := os.Create(filename)
      if err != nil {
        fmt.Println(err)
        os.Exit(1)
      }
      io.Copy(writer, tarBallReader)
      err = os.Chmod(filename, os.FileMode(header.Mode))
      if err != nil {
        fmt.Println(err)
        os.Exit(1)
      }
      writer.Close()
    default:
      fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
      filename)
    }
  }
}
1
1
1
2019-04-23 02:33:30 +0000

A partire da Windows 10 build 17063, tar e curl sono supportati, quindi è possibile decomprimere un file .tar.gz in un solo passo usando il comando tar, come sotto.

tar -xzvf your_archive.tar.gz

Scrivi tar --help per maggiori informazioni su tar.

0
Advertisement
0
0
2018-08-31 08:08:02 +0000
Advertisement

7za funziona correttamente come segue:

7za.exe x D:\pkg-temp\Prod-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:\pkg-temp\Prod-Rtx-Service
Advertisement

Domande correlate

3
12
8
9
4
Advertisement
Advertisement