Ubuntu Forums Archive Viewer

TIP: extract .xz format

Archived thread 1116012 from Tutorials. Markdown source: Tutorials/thread_1116012_TIP_extract_.xz_format.md

Original URL About this archive
#1

tar Jxf coreutils-7.2.tar.xz
#2

I tried your code. I got this error message.

~$ tar Jxf coreutils-7.4.tar.xz
tar: invalid option -- J
Try `tar --help' or `tar --usage' for more information.
#3

It works when you use the minus sign: - tar -Jxf <filename>

#4

Add this to your ~/.bashrc

extract () {
   if [ -f $1 ] ; then
       case $1 in
	*.tar.bz2)	tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
	*.tar.gz)	tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
	*.tar.xz)	tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
	*.bz2)		bunzip2 $1 && cd $(basename "$1" /bz2) ;;
	*.rar)		unrar x $1 && cd $(basename "$1" .rar) ;;
	*.gz)		gunzip $1 && cd $(basename "$1" .gz) ;;
	*.tar)		tar xvf $1 && cd $(basename "$1" .tar) ;;
	*.tbz2)		tar xvjf $1 && cd $(basename "$1" .tbz2) ;;
	*.tgz)		tar xvzf $1 && cd $(basename "$1" .tgz) ;;
	*.zip)		unzip $1 && cd $(basename "$1" .zip) ;;
	*.Z)		uncompress $1 && cd $(basename "$1" .Z) ;;
	*.7z)		7z x $1 && cd $(basename "$1" .7z) ;;
	*)		echo "don't know how to extract '$1'..." ;;
       esac
   else
       echo "'$1' is not a valid file!"
   fi
 }

Now just type "extract filename" and you're golden.

#5

If the file is just [FONT="Courier New"]something.xz[/FONT] (without .tar) then

tar xvJf something.xz

will not work. You will get the following error (or similar)

tar: Record size = 16 blocks
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

Instead, just type

unxz something.xz

:-D

#6

This is my extract script that uses MIME to determine the format plus it has protection for extracting into the current dir:

https://github.com/lzap/dancepill/blob/master/e

Patches welcome.

#7

tar -Jxvf filename.tar.xz please use capital J

#8

Thread closed because:

It is ancient.

It doesn't fulfill the posting requirements for tutorials current at the time of the OP, nor does it fulfill current guidelines.

If anyone needs help with extracting .xz files, please start a thread in a support section.