Como descompactar arquivo TAR ou qualquer arquivo compactado, usando o Linux ou MacOS

Fala pessoal, uma das dores de todo mundo que usa terminal, preponderantemente, é descompactar arquivos de extensões diversas. Tirando o ZIP que para descompactar usamos o UNZIP, teremos de lembrar opções para adicionar no comando TAR.

Pensando em criar um "untar" acabei encontrando numa pesquisa o unar, que é tudo o que procuramos. Super simples e prático de usar, bastando executar: unar arquivo-a-descompactar.ext .

Me parece que já vem como default em várias distribuições, mas todavia segue o repositório do Github para quem precisar:

Github: https://github.com/ashang/unar

Comando básico para extração de qualquer arquivo compactado, sem precisar usar opções, use apenas o nome do app mais o arquivo:

~ unar file-to-extract.ext

Existem opções a acrescentar e vou descrever abaixo:

~ unar --help
unar v1.10.1, a tool for extracting the contents of archive files.
Usage: unar [options] archive [files …]

Available options:
-output-directory (-o) The directory to write the contents of the archive to. Defaults to the current directory. If set to a single dash (-), no files will be created, and all data will be output to
stdout.
-force-overwrite (-f) Always overwrite files when a file to be unpacked already exists on disk. By default, the program asks the user if possible, otherwise skips the file.
-force-rename (-r) Always rename files when a file to be unpacked already exists on disk.
-force-skip (-s) Always skip files when a file to be unpacked already exists on disk.
-force-directory (-d) Always create a containing directory for the contents of the unpacked archive. By default, a directory is created if there is more than one top-level file or folder.
-no-directory (-D) Never create a containing directory for the contents of the unpacked archive.
-password (-p) The password to use for decrypting protected archives.
-encoding (-e) The encoding to use for filenames in the archive, when it is not known. If not specified, the program attempts to auto-detect the encoding used. Use "help" or "list" as the
argument to give a listing of all supported encodings.
-password-encoding (-E) The encoding to use for the password for the archive, when it is not known. If not specified, then either the encoding given by the -encoding option or the auto-detected encoding
is used.
-indexes (-i) Instead of specifying the files to unpack as filenames or wildcard patterns, specify them as indexes, as output by lsar.
-no-recursion (-nr) Do not attempt to extract archives contained in other archives. For instance, when unpacking a .tar.gz file, only unpack the .gz file and not its contents.
-copy-time (-t) Copy the file modification time from the archive file to the containing directory, if one is created.
-forks (-k) How to handle Mac OS resource forks. "visible" creates AppleDouble files with the extension ".rsrc", "hidden" creates AppleDouble files with the prefix "._", and "skip" discards
all resource forks. Defaults to "visible".
-quiet (-q) Run in quiet mode.
-version (-v) Print version and exit.
-help (-h) Display this information.

Quando citamos qualquer arquivo é suportado, claro que existem algumas exceções como DEB, DMG, PAR, SHG, ACE 2.0 (também padrão WinACE) e Amiga.

Exemplos de extensões suportadas vão das mais comuns a muitas outras, como: ZIP, RAR, 7Z (sem encriptação), TAR, GZIP, BZIP2, LZMA, XZ, CAB, MSI, NSIS, EXE, ISO, SPLIT (faz a junção básica), STUFFIT (sem encriptação), STUFFIT X, DISKDOUBLER, COMPACT PRO (sem encriptação), PACKIT, CPIO, Z, ARJ (sem split), ARC, PAK, ACE (padrão DOS), ZOO, LZH, ADF, DMS, LZX, POWERPACKER, LBR, SQUEEZE, CRUNCH, XAR, RPM, ALZIP (sem encriptação), NSA, SAR, NDS, ZIPX e outras extensões não usuais suportadas pela biblioteca libxad.

Gostou deste conteúdo, tem alguma sugestão ou outra dúvida? Deixe sua mensagem.

Me siga no Twitter @danielsob

A você que se interessa em realizar tutoriais mais interativos com conteúdos como este, respeite a pesquisa e construção de conteúdo, há tempo e conhecimento empenhado nisto. Lembre-se se citar a fonte. Todos ganham com isto.