Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folder Renaming After Tar Extraction

Tags:

bash

shell

tar

I have a tarball, myarchive.tar.gz. When I uncompress it using "tar -zxvf myarchive.tar.gz", it creates a folder myarchive-x980-2303-ssioo. What's the easiest way to automatically rename the extracted folder to ensure it matches the name of the archive? I've checked tar's manpage, but it doesn't seem to have an option for this.

like image 873
Cerin Avatar asked May 27 '10 00:05

Cerin


2 Answers

Manually create folder, and strip components from tarball:

archive=my.tar.gz
mkdir ${archive%.tar*} 
tar --extract --file=${archive} --strip-components=1 --directory=${archive%.tar*}
like image 81
Jürgen Hötzel Avatar answered Oct 31 '22 20:10

Jürgen Hötzel


mkdir pretty_name && tar xf ugly_name.tar -C pretty_name --strip-components 1

from https://unix.stackexchange.com/questions/11018/how-to-choose-directory-name-during-untarring

like image 31
陈永林 Avatar answered Oct 31 '22 21:10

陈永林