I tried to extract filename1.tar.gz
but I got the different name which is the folder archive inside lets say archive_folder
; how I can extract the tar.gz
with the same name of the filename.
I use this command:
tar -xzvf filename1.tar.gz
also I want to write a command to extract multiple tar.gz
with one line.
mkdir -p filename1; tar xfz filename1.tar.gz -C filename1
. or with the tarfile's name in a variable:f='filename1.tgz'; bn="$(basename "$f" ".tgz")"; mkdir -p "$bn"; tar xfz "$f" -C "$bn"
. If necessary, also use GNU tar's--transform
or--strip-components
options to remove any unwanted path elements likearchive_folder/
. The linked answer provides examples of everything you need to do. – cas Sep 18 '21 at 05:15