Glam Prestige Journal

Bright entertainment trends with youth appeal.

I know that I can run

$ tar xf somefile.tar.gz -C somedir

to 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?

1

1 Answer

Using the GNU tar command, you can do this:

tar -xf somefile.tar.gz --one-top-level=somedir

From 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).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy