0

I have the following gzip file: hdf5-1.8.18.tar.gz. When I unzip the file with the following command:

gunzip < hdf5-1.8.18.tar.gz | tar xf -

It unzips into the created following directory: hdf5-1.8.18. This directory is not really convenient to use cause of the "-" therefore I changed the name of the directory by using the following command:

mv hdf5-1.8.18 hdf5

But using this command I lost the "1.8.18" version information: Therefore I can do an ugly workaround like:

mkdir hdf5
mv hdf5-1.8.18 hdf5/1.8.18

I find this solution quiet ugly therefore I would like to know if there is no more straight forward way to do that. Thank you!

2 Answers 2

2

You might want to take a look at the -C option of tar.

tar zxf hdf5-1.8.18.tar.gz -C hdf

would unzip, untar, & place the directory under the hdf/ diretory.

2

First of all it'd be easier if you re-worded your question a bit. Feels easily solvable via a script of some sort. Following should work in a BASH script. Run it with filename as first argument. For instance, "./change_name_script.sh hdf5-1.8.18.tar.gz" and it will work the way you want it

#!/bin/bash
filename=$1

gunzip < $filename | tar xf -
move_filename=$(echo $filename | sed -r 's/.tar.gz$//')
first_part=$(echo "$move_filename" | sed -r 's/-.*$//')
second_part=$(echo "$move_filename" | sed -r 's/^.*-//')

mkdir $first_part
mv $move_filename $first_part/$second_part

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .