The tar
command has option to extra a file (file_name.tgz
) into given directory (directory_name
). ie.,
tar -zxf file_name.tgz -C directory_name
But it fails, if I try to run the above command, without creating directory (directory_name
) prior to running this. Following is the error I got:
tar: directory_name: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
Is there any option present in tar command to create this directory if not present?
The present work around I have, is by running mkdir -p directory_name
in prior.
mkdir -p directory && tar -xf filename.tgz -C $_
, $_ will contain the last argument of the previous command. – Oct 28 '20 at 07:49mkdir
fails? It would be very rare, but still. – Mithun B Oct 28 '20 at 07:59mkdir -p
will create the parent path too, so it will not fail, while the user has enough write permissions. @bac0n, please convert your comment into an answer. – pa4080 Oct 28 '20 at 08:30&&
. I just overlook without paying much heed. – Mithun B Oct 28 '20 at 10:34