3 ms·
> One oddity not explained is tar allowing multi options crammed together without any dash, that nobody can ever remember (eg. tar xvf archive.tar) This is a B
by LeoPanthera 5y ago
> One oddity not explained is tar allowing multi options crammed together without any dash, that nobody can ever remember (eg. tar xvf archive.tar)
This is a BSDism, and it's deprecated even there. bsdtar allows it for compatibility with old scripts.
GNUtar has long-switches for all options, which makes it considerably easier to use and understand, for example:
gtar --create --file etc.tar --verbose /etc
- nsajko 5y ago> This is a BSDism No, it was like that when Tar was first introduced, as part of Seventh Edition Unix: https://man.cat-v.org/unix_7th/1/tar https://man.cat-v.org/unix_7th/1/tar https://en.wikipedia.org/wiki/Tar_(computing) https://en.wikipedia.org/wiki/Tar_(computing)
- eesmith 5y agoSee also "tap" from v1, to "manipulate DECtape", described at http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersManual_Nov71.pdf http://www.bitsavers.org/pdf/bellLabs/unix/UNIX_ProgrammersM... , p94 of the pdf: > tap [key] [name ...] > The function portion of the key is specified by one of the following letters ... For example, "x" to extract. > The following characters may be used in addition to the letter which selects the function desired For example, "v" for verbose.
- elteto 5y ago> that nobody can ever remember These have gone a long way for me: tar xzf <in> eXtract Zipped File tar czf <out> <in> Create Zipped File Anything more complicated and I have to google.
- aendruk 5y agoNo need for the mnemonic device when you can literally type “--extract --gzip --file”, which reads as a sentence and has no trouble adapting to --xz or --zstd.
- Macha 5y agoThe `-z` on extract is not needed on basically most modern tar implementations (OpenBSD's is I believe the one outlier). tar -xf foo.tar.gz (or .xz, .bz2, .zst, etc.) will work, auto detect the archive type and extract.
- yourad_io 5y agoOh this is great, I remember z for gzip but always have to look up J vs j for bzip2/xz
- cb321 5y agoWith https://github.com/c-blake/nio/blob/main/utils/catz.nim https://github.com/c-blake/nio/blob/main/utils/catz.nim you can get similar format agnostic decoding/decompression not just in tar but in any pipeline context based on magic numbers, not filename extensions and even doing the copy loop needed for unseekable inputs to replace the early read -- e.g. cat foo.gz|catz|less works..
- 1vuio0pswjnm7 5y agoOpenBSD, which is a fork of NetBSD, is not the only "outlier".^1 For many years, NetBSD tar has autodetected bzip2 compression. tar xzf 1.tar.bz2 will work on gzip as well as bzip2. Whereas GNU tar still requires "j" instead^2 tar xjf 1.tar.bz2 1. For example, FreeBSD or MacOS tar is BSD tar. It will autodetect bzip2 compression. 2. The GNU tar included with VoidLinux still requires z or j. The pax(1) utility is the POSIX solution to these incompatibilities.
- Macha 5y agoVoid Linux appears to include GNU tar 1.34 The following should work, it worked on my Arch Linux install (but note that auto detection is not a "new" feature to GNU tar, I've been using it for at least 5 years) echo "Hello" > foo.txt tar cjf foo.tar.bz2 foo.txt rm foo.txt tar xf foo.tar.bz2 cat foo.txt and produce "Hello" To be clear, I'm not saying the following should work tar xzf foo.tar.bz2 What should work is: tar xf foo.tar.bz2 And for proof this is GNU tar $ tar --version tar (GNU tar) 1.34 Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by John Gilmore and Jay Fenlason.
- kergonath 5y ago> gtar --create --file etc.tar --verbose /etc That’s considerably more cumbersome than tar -cvf.