Create target directory when extracting tarball
Clash Royale CLAN TAG#URR8PPP
up vote
14
down vote
favorite
Is it possible to create a target directory, similar to mkdir -p
, where I can define a non-existent target directory within my tar command, and tar will create the directory for me?
I know I can redirect the output to a directory using tar -C /target/dir
, but this doesn't work if the target directory is non-existent.
directory tar
add a comment |Â
up vote
14
down vote
favorite
Is it possible to create a target directory, similar to mkdir -p
, where I can define a non-existent target directory within my tar command, and tar will create the directory for me?
I know I can redirect the output to a directory using tar -C /target/dir
, but this doesn't work if the target directory is non-existent.
directory tar
3
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02
add a comment |Â
up vote
14
down vote
favorite
up vote
14
down vote
favorite
Is it possible to create a target directory, similar to mkdir -p
, where I can define a non-existent target directory within my tar command, and tar will create the directory for me?
I know I can redirect the output to a directory using tar -C /target/dir
, but this doesn't work if the target directory is non-existent.
directory tar
Is it possible to create a target directory, similar to mkdir -p
, where I can define a non-existent target directory within my tar command, and tar will create the directory for me?
I know I can redirect the output to a directory using tar -C /target/dir
, but this doesn't work if the target directory is non-existent.
directory tar
directory tar
edited Aug 28 '15 at 2:49
asked Nov 25 '11 at 3:49
wulfgarpro
188128
188128
3
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02
add a comment |Â
3
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02
3
3
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
27
down vote
accepted
mkdir -p /target/dir && tar -C /target/dir
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
Minor suggested change:mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
add a comment |Â
up vote
5
down vote
This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder
mkdir
makes the folder although i dont quite understand the -p
switch. &&
lets you execute a second command. i used typical tar -switches but at the end -C
is used to change directories and extract to that location needed.
reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create/create
if it doesn't exist.
â Antonio Pérez
Oct 21 '15 at 13:40
add a comment |Â
up vote
1
down vote
If you don't know the paths to create...
Get the needed paths from the tar file, then create them...
for P in `tar tvf tarfile.tar |tr -s [:space:] |cut -d' ' -f6`; do
C=`echo "$P: -1"` #get the last character
if [ $C = '/' ]; then
echo "Found directory: $P"
mkdir -p $P
fi
done
add a comment |Â
up vote
0
down vote
tar -xvf bash.html_node.tar.gz --one-top-level
from man page of tar command
--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 stanâÂÂ
dard compression suffixes recognizable by --auto-compress).
New contributor
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
27
down vote
accepted
mkdir -p /target/dir && tar -C /target/dir
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
Minor suggested change:mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
add a comment |Â
up vote
27
down vote
accepted
mkdir -p /target/dir && tar -C /target/dir
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
Minor suggested change:mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
add a comment |Â
up vote
27
down vote
accepted
up vote
27
down vote
accepted
mkdir -p /target/dir && tar -C /target/dir
mkdir -p /target/dir && tar -C /target/dir
answered Nov 25 '11 at 4:21
V for V
28632
28632
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
Minor suggested change:mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
add a comment |Â
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
Minor suggested change:mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
2
2
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
No spoonfeeding, straight and to the point.
â Amado Martinez
Oct 31 '16 at 6:56
5
5
Minor suggested change:
mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
Minor suggested change:
mkdir -p /target/dir && tar -C $_
â Mark Melville
Jan 13 '17 at 22:41
add a comment |Â
up vote
5
down vote
This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder
mkdir
makes the folder although i dont quite understand the -p
switch. &&
lets you execute a second command. i used typical tar -switches but at the end -C
is used to change directories and extract to that location needed.
reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create/create
if it doesn't exist.
â Antonio Pérez
Oct 21 '15 at 13:40
add a comment |Â
up vote
5
down vote
This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder
mkdir
makes the folder although i dont quite understand the -p
switch. &&
lets you execute a second command. i used typical tar -switches but at the end -C
is used to change directories and extract to that location needed.
reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create/create
if it doesn't exist.
â Antonio Pérez
Oct 21 '15 at 13:40
add a comment |Â
up vote
5
down vote
up vote
5
down vote
This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder
mkdir
makes the folder although i dont quite understand the -p
switch. &&
lets you execute a second command. i used typical tar -switches but at the end -C
is used to change directories and extract to that location needed.
reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive
This made more sense to me mkdir -p /create/folder && tar -zxf haroopad-v0.13.0_x64.tar.gz -C /create/testfolder
mkdir
makes the folder although i dont quite understand the -p
switch. &&
lets you execute a second command. i used typical tar -switches but at the end -C
is used to change directories and extract to that location needed.
reference: extract-files-contained-in-archive-tar-gz-to-new-directory-named-archive
edited May 23 '17 at 12:39
Communityâ¦
1
1
answered Feb 1 '15 at 1:40
Gr4cchus
5113
5113
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create/create
if it doesn't exist.
â Antonio Pérez
Oct 21 '15 at 13:40
add a comment |Â
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create/create
if it doesn't exist.
â Antonio Pérez
Oct 21 '15 at 13:40
2
2
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
The -p switch will not throw an error if the directory already exists.
â David
Sep 3 '15 at 21:10
@David it will also create any leading non-existing directories, i.e. it'll create
/create
if it doesn't exist.â Antonio Pérez
Oct 21 '15 at 13:40
@David it will also create any leading non-existing directories, i.e. it'll create
/create
if it doesn't exist.â Antonio Pérez
Oct 21 '15 at 13:40
add a comment |Â
up vote
1
down vote
If you don't know the paths to create...
Get the needed paths from the tar file, then create them...
for P in `tar tvf tarfile.tar |tr -s [:space:] |cut -d' ' -f6`; do
C=`echo "$P: -1"` #get the last character
if [ $C = '/' ]; then
echo "Found directory: $P"
mkdir -p $P
fi
done
add a comment |Â
up vote
1
down vote
If you don't know the paths to create...
Get the needed paths from the tar file, then create them...
for P in `tar tvf tarfile.tar |tr -s [:space:] |cut -d' ' -f6`; do
C=`echo "$P: -1"` #get the last character
if [ $C = '/' ]; then
echo "Found directory: $P"
mkdir -p $P
fi
done
add a comment |Â
up vote
1
down vote
up vote
1
down vote
If you don't know the paths to create...
Get the needed paths from the tar file, then create them...
for P in `tar tvf tarfile.tar |tr -s [:space:] |cut -d' ' -f6`; do
C=`echo "$P: -1"` #get the last character
if [ $C = '/' ]; then
echo "Found directory: $P"
mkdir -p $P
fi
done
If you don't know the paths to create...
Get the needed paths from the tar file, then create them...
for P in `tar tvf tarfile.tar |tr -s [:space:] |cut -d' ' -f6`; do
C=`echo "$P: -1"` #get the last character
if [ $C = '/' ]; then
echo "Found directory: $P"
mkdir -p $P
fi
done
edited Jan 30 at 19:26
Weijun Zhou
1,444121
1,444121
answered Jan 30 at 18:34
ckroger
112
112
add a comment |Â
add a comment |Â
up vote
0
down vote
tar -xvf bash.html_node.tar.gz --one-top-level
from man page of tar command
--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 stanâÂÂ
dard compression suffixes recognizable by --auto-compress).
New contributor
add a comment |Â
up vote
0
down vote
tar -xvf bash.html_node.tar.gz --one-top-level
from man page of tar command
--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 stanâÂÂ
dard compression suffixes recognizable by --auto-compress).
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
tar -xvf bash.html_node.tar.gz --one-top-level
from man page of tar command
--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 stanâÂÂ
dard compression suffixes recognizable by --auto-compress).
New contributor
tar -xvf bash.html_node.tar.gz --one-top-level
from man page of tar command
--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 stanâÂÂ
dard compression suffixes recognizable by --auto-compress).
New contributor
New contributor
answered 8 mins ago
Alaa Ahmad M. Zakaria
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f25311%2fcreate-target-directory-when-extracting-tarball%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
If it isn't possible, you could always create a shell alias.
â n0pe
Nov 25 '11 at 4:02