Cerin
Cerin

Reputation: 64820

Folder Renaming After Tar Extraction

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.

Upvotes: 19

Views: 7420

Answers (2)

陈永林
陈永林

Reputation: 43

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

Upvotes: 2

Jürgen Hötzel
Jürgen Hötzel

Reputation: 19747

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*}

Upvotes: 32

Related Questions