Sample Header Ad - 728x90

Extract archive with BSD tar to directory with same basename

1 vote
2 answers
1365 views
GNU tar allows to extract the contents of an archive to a directory named after the basename of the archive. $ touch foobar $ gnutar czf archive.tar.gz foobar $ gnutar --one-top-level -xf archive.tar.gz $ ls archive/foobar archive/foobar I can get the same result with BSD tar by running multiple commands. $ destdir=$(basename archive.tar.gz .tar.gz) $ mkdir $destdir $ bsdtar -C $destdir -xf archive.tar.gz $ ls archive/foobar archive/foobar I would however like to run a _single_ command just as with GNU tar. One could of course wrap the commands into shell script or shell function but I'm wondering if there is some _builtin_ of BSD tar that produces the same result thus requiring only a single command? --- Background: I would like to use BSD tar because GNU tar currently does not seem to support extended attributes on non-Linux plattforms, at least GNU tar installed via Homebrew on macOS is currently not compiled with extended attributes support.
Asked by Stefan Schmidt (121 rep)
Nov 26, 2022, 01:34 PM
Last activity: Jan 11, 2023, 05:59 PM