Reputation: 139
i want to extract tar file. but, terminal is error output.
i want to solve the error. could you help me?
this is terminal cmd
$ tar xvzf test.tar -C /dir/
this is error output
# gzip: invalid magic
# tar: Child returned status 1
# tar: Error exit delayed from previous errors
Upvotes: 9
Views: 17623
Reputation: 41
Put the below code into your bashrc then just :
UZ file.tar
you can also use it with zip, 7z, tar.gz, or gz.
in your bashrc:
UZ() {
# Extract file name and extension separately
f_name="$(basename "$1" | awk -F. 'BEGIN{OFS="_"} {if ($(NF-1) == "tar") {ext = $(NF-1) "." $NF; NF-=2} else {ext = $NF; NF--}; print $0}')"
f_ext="$(echo "$1" | awk -F. '{if ($(NF-1) == "tar") {print $(NF-1) "." $NF} else {print $NF}}')"
# Determine the last or last two dots to perform the actions
case "$f_ext" in
"zip")
echo "unzipping zip to $f_name"
mkdir "$f_name"
unzip "$1" -d "$f_name"
;;
"tar.gz" | "tgz")
echo "unzipping tar.gz to $f_name"
mkdir "$f_name"
tar -zxvf "$1" -C "$f_name" --strip-components 1
;;
"tar")
echo "unzipping tar to $f_name"
mkdir "$f_name"
tar -xvf "$1" -C "$f_name"
;;
"gz")
echo "unzipping gz to $f_name"
mkdir "$f_name"
gunzip -c "$1" > "$f_name"
;;
"7z")
echo "unzipping 7z to $f_name"
mkdir "$f_name"
7z x "$1" -o"$f_name"
;;
*)
echo "unknown file type: $f_ext"
;;
esac
}
Upvotes: 1
Reputation: 389
You are running tar xzvf, which extracts a compressed tar, but the filename given is tar, which is just a tar file, not compressed. Try without the z.
tar xvf ...
Upvotes: 20