You are not logged in.

#1 2008-06-09 03:06:40

nilsHaus
Member
Registered: 2007-06-22
Posts: 69

tar -xvf does everything?

It doesn't matter whether things are .tar, .tar.bz, .tar.gz2, it seems like whenever I do tar -xvf it just does it for me. On the one hand this rocks, but on the other hand this contradicts everything on the internet and the man pages...So what does tar -xvf do?

Offline

#2 2008-06-09 03:10:30

shazeal
Member
From: New Zealand
Registered: 2007-06-05
Posts: 341

Re: tar -xvf does everything?

Saves one second of your life everytime you unpack something? big_smile

It just auto detects the format.

Offline

#3 2008-06-09 03:31:39

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: tar -xvf does everything?

really? I have to use -xf for tar, -xzf for tar.gz, and -xjf for tar.bz2 =P

Last edited by Stythys (2008-06-09 03:32:05)


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#4 2008-06-09 03:36:13

peets
Member
From: Montreal
Registered: 2007-01-11
Posts: 936
Website

Re: tar -xvf does everything?

cool, I didn't know this. I always did "tar xzf" or "tar xjf"... It might be in the "info pages" tongue

Offline

#5 2008-06-09 04:46:34

underpenguin
Member
Registered: 2007-02-01
Posts: 116

Re: tar -xvf does everything?

Wow. I also have been -xzvf-ing and -xjvf-ing for years. You learn something new every day. Thanks smile

Offline

#6 2008-06-09 06:30:42

delor
Member
From: Poland
Registered: 2008-02-02
Posts: 62
Website

Re: tar -xvf does everything?

I have just put this in .bashrc

# extract archives -- usage: extract <file>
extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2) tar xjf $1 ;;
            *.tar.gz) tar xzf $1 ;;
            *.bz2) bunzip2 $1 ;;
            *.rar) unrar e $1 ;;
            *.gz) gunzip $1 ;;
            *.tar) tar xf $1 ;;
            *.tbz2) tar xjf $1 ;;
            *.tgz) tar xzf $1 ;;
            *.zip) unzip "$1" ;;
            *.Z) uncompress $1 ;;
            *.7z) 7z x $1 ;;
            *) echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

Offline

#7 2008-06-09 07:04:48

sniffles
Member
Registered: 2008-01-23
Posts: 275

Re: tar -xvf does everything?

What the heck, when did this happen?

Offline

#8 2008-06-09 20:48:36

nilsHaus
Member
Registered: 2007-06-22
Posts: 69

Re: tar -xvf does everything?

Yeah, I guess this is pretty cool. So is anything in xvf unnecessary? What does f do?

Offline

#9 2008-06-09 20:54:13

Misfit138
Misfit Emeritus
From: USA
Registered: 2006-11-27
Posts: 4,189

Re: tar -xvf does everything?

nilsHaus wrote:

Yeah, I guess this is pretty cool. So is anything in xvf unnecessary? What does f do?

It tells 'tar' that you are extracting a 'f'ile.
Check out the tar man page for more.

Offline

#10 2008-06-09 22:04:33

shazeal
Member
From: New Zealand
Registered: 2007-06-05
Posts: 341

Re: tar -xvf does everything?

You can just tar xf if you want, v is verbose. f just tells it you are giving it a file to extract.

Offline

#11 2008-06-09 22:48:20

gazj
Member
From: /home/gazj -> /uk/cambs
Registered: 2007-02-09
Posts: 681
Website

Re: tar -xvf does everything?

I have always done xf or xvf, must be for a couple of years (or even more) I guess.  Never knew there were switches for different archive types.  Now I feel like a real newb

Offline

#12 2008-06-10 00:46:41

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: tar -xvf does everything?

I was surprised too when I found out it autodetects.

Offline

#13 2008-06-10 03:06:19

nilsHaus
Member
Registered: 2007-06-22
Posts: 69

Re: tar -xvf does everything?

Should I be worried if tar doesn't have a man page (I would've looked there before wasting your time, Misfit)?

Offline

#14 2008-06-10 03:16:57

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,398
Website

Re: tar -xvf does everything?

nilsHaus wrote:

Should I be worried if tar doesn't have a man page

There is one...  Check that you have merged /etc/profile.pacnew.

Offline

#15 2008-06-10 09:52:16

anykey
Member
From: Trier, Germany
Registered: 2004-06-12
Posts: 79

Re: tar -xvf does everything?

this is GNU tar and bsdtar only. Other tars won't necessarily do it.

Offline

#16 2008-06-11 17:17:14

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: tar -xvf does everything?

I weep for all of those wasted j's and z's that have been typed in vain.

Offline

#17 2008-06-11 21:46:32

elasticdog
Member
From: Washington, USA
Registered: 2005-05-02
Posts: 995
Website

Re: tar -xvf does everything?

man...I didn't know that either. I feel like such an old-timer!

Offline

#18 2008-06-12 00:41:15

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: tar -xvf does everything?

shazeal wrote:

Saves one second of your life everytime you unpack something? big_smile

It just auto detects the format.

If it matches what's in it wink.

I don't know what the - is for (GNU tar doesn't really need it afaik, maybe for compatibility reasons), tar xf should be plenty most of the time.

Last edited by B (2008-06-12 00:42:11)


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

#19 2009-01-08 16:26:16

onguarde
Member
Registered: 2008-09-14
Posts: 144

Re: tar -xvf does everything?

delor wrote:

I have just put this in .bashrc

# extract archives -- usage: extract <file>
extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2) tar xjf $1 ;;
            *.tar.gz) tar xzf $1 ;;
            *.bz2) bunzip2 $1 ;;
            *.rar) unrar e $1 ;;
            *.gz) gunzip $1 ;;
            *.tar) tar xf $1 ;;
            *.tbz2) tar xjf $1 ;;
            *.tgz) tar xzf $1 ;;
            *.zip) unzip "$1" ;;
            *.Z) uncompress $1 ;;
            *.7z) 7z x $1 ;;
            *) echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

I keep getting the error below when the above is pasted in .bashrc.

bash: /home/xslash/.bashrc: line 110: syntax error near unexpected token `}'
bash: /home/xslash/.bashrc: line 110: `}'

The weird thing is I can't find anything different from the above. Would deeply appreciate if someone could enlighten me.

Thanks.

Offline

#20 2009-01-08 17:20:46

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: tar -xvf does everything?

onguarde: why not try atool?

It is basically a fleshed out version but with more features and it protects against tar bombs.

Offline

#21 2009-01-08 19:27:16

userlander
Member
Registered: 2008-08-23
Posts: 413

Re: tar -xvf does everything?

hooray! seriously, I hated having to check my brain against the extension every time. Now I just have to retrain my fingers. big_smile

Offline

#22 2009-01-09 13:12:08

.:B:.
Forum Fellow
Registered: 2006-11-26
Posts: 5,819
Website

Re: tar -xvf does everything?

shazeal wrote:

You can just tar xf if you want, v is verbose. f just tells it you are giving it a file to extract.

+1

I always use

tar xf $archive

The thing is, a lot of Linux/UNIX apps check the first bytes of a file (the header). That is what e.g. the 'file' utility does. Tar does probably the same, so it does not need you to determine what type of file it is smile. As is said often, extensions are for humans (and Windows tongue).


Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

Offline

Board footer

Powered by FluxBB