I know that I can run
$ tar xf somefile.tar.gz -C somedirto extract the tar.gz file to somedir, but it requires somedir exists first.
Is there a way to extract to a directory and create the directory on the fly if it does not exist?
11 Answer
Using the GNU tar command, you can do this:
tar -xf somefile.tar.gz --one-top-level=somedirFrom man 1 tar:
--one-top-level[=DIR] Extract all files into DIR, or, if used without argument, into a subdirectory named by the base name of the archive (minus standard compression suffixes recognizable by --auto-compress).