Create target directory when extracting tarball
mkdir -p /target/dir && tar -C /target/dir
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 standard compression suffixes recognizable by
--auto-compress
).
----- test
test 1
tar zxvf ../aaa.tgz --one-top-level
aaa/
aaa/222
aaa/111
tree aaa
aaa/
├── 111
└── 222
// if tgz name same as root_dir of archive, no other effect
test 2
mv ../aaa.tgz ../bbb.tgz
tar zxvf ../bbb.tgz --one-top-level
aaa/
aaa/222
aaa/111
tree bbb
bbb
└── aaa
├── 111
└── 222
// if tgz name not same as root_dir of archive, create a top-level dir
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 don't 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