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

Hoe kan ik een .tar.gz in één stap uitpakken (met 7-Zip)?

Advertisement

Ik gebruik 7-Zip op Windows XP en telkens als ik een .tar.gz bestand download, heb ik twee stappen nodig om het bestand (of de bestanden) volledig uit te pakken.

  1. Ik klik met de rechtermuisknop op het voorbeeld.tar.gz bestand en kies 7-Zip –> Hier uitpakken uit het contextmenu.
  2. Dan pak ik het resulterende voorbeeld.tar bestand en klik opnieuw met de rechtermuisknop en kies 7-Zip –> Hier uitpakken uit het contextmenu.

Is er een manier via het contextmenu om dit in één stap te doen?

Advertisement
Advertisement

Antwoorden (7)

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

Niet echt. Een .tar.gz of .tgz bestand bestaat eigenlijk uit twee formaten: .tar is het archief, en .gz is de compressie. Dus de eerste stap decomprimeert, en de tweede stap pakt het archief uit.

Om dit alles in één stap te doen, heb je het tar programma nodig. Cygwin ](http://www.cygwin.com/) bevat dit.

tar xzvf foobaz.tar.gz

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

Je zou het ook “in één stap” kunnen doen door het bestand in de 7-zip GUI te openen: Open het .tar.gz bestand, dubbelklik op het meegeleverde .tar bestand, pak die bestanden dan uit naar de locatie van je keuze.

Er is een lang lopende thread hier van mensen die vragen/stemmen voor één-stap afhandeling van tgz en bz2 bestanden. Het gebrek aan actie tot nu toe geeft aan dat het niet gaat gebeuren totdat iemand een stap zet en een zinvolle bijdrage levert (code, geld, iets).

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

Oude vraag, maar ik zat ermee te worstelen vandaag dus hier is mijn 2c. De 7zip commandline tool “7z.exe” (ik heb v9.22 geïnstalleerd) kan naar stdout schrijven en van stdin lezen, dus je kunt het zonder het tussenliggende tar bestand doen door een pipe te gebruiken:

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

Waar:

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

Zie het helpbestand (7-zip.chm) in de installatiedirectory voor meer info over de opdrachtregelcommando’s en schakelaars.

U kunt een context menu item maken voor .tar.gz/.tgz bestanden dat het bovenstaande commando oproept met regedit of een 3rd party tool zoals stexbar .

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

Vanaf 7-zip 9.04 is er een commandoregeloptie om de gecombineerde extractie uit te voeren zonder tussentijdse opslag te gebruiken voor het gewone .tar-bestand:

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

-tgzip is nodig als het invoerbestand de naam .tgz heeft in plaats van .tar.gz.

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

Je gebruikt Windows XP, dus je zou Windows Scripting Host standaard geïnstalleerd moeten hebben. Met dat gezegd zijnde, hier is een WSH JScript script om te doen wat je nodig hebt. Kopieer de code naar een bestand met de naam xtract.bat of iets van die strekking (kan van alles zijn, zolang het maar de extensie .bat heeft), en voer het uit:

xtract.bat example.tar.gz

Standaard zal het script de map van het script controleren, evenals de PATH omgevingsvariabele van je systeem voor 7z.exe. Als u wilt wijzigen hoe het script zoekt, kunt u de SevenZipExe-variabele bovenaan het script wijzigen in wat u wilt dat de naam van het uitvoerbare bestand is. (Bijvoorbeeld 7za.exe of 7z-real.exe) U kunt ook een standaardmap instellen voor het uitvoerbare bestand door SevenZipDir te wijzigen. Dus als 7z.exe op C:\Windows\system32z.exe staat, zou je zetten:

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

Hoe dan ook, hier is het 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

Zoals u kunt zien is 7-Zip hier niet erg goed in. Mensen vragen al sinds 2009 om tarball atomic operation. Hier is een klein programma ](https://socketloop.com/tutorials/golang-untar-or-extract-tar-ball-archive-example)(490 KB) in Go dat het kan, ik compileerde het voor u.

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

Vanaf Windows 10 build 17063 worden tar en curl ondersteund, daarom is het mogelijk om een .tar.gz bestand in één stap uit te pakken met het tar commando, zoals hieronder.

tar -xzvf your_archive.tar.gz

Type tar --help voor meer informatie over tar.

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

7za werkt goed zoals hieronder:

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

Gerelateerde vragen

3
12
8
9
13
Advertisement
Advertisement