News for hackers. Stuff that matters.
Re:Learn just enough Linux to get things done by ivanhoe on Thursday November 16, 2017 @10:15AM (#15713252)
Over years I've heard a lot of complains on tar being hard to use, but in real-life I really ever had to use only these two commands: tar zcvf and tar zxvf. It's actually quite easy to remember: tar Zip Compress Verbose File, and tar Zip eXtract Verbose File.
Re:Learn just enough Linux to get things done by nerdponx on Thursday November 16, 2017 @11:00AM (#15713691)
It's even easier than that! Less memorization, more understanding.

You can think of Tar arguments as either subcommands or options. The dashes are optional

The "subcommands" are x (extract), c (create), t (list), among others.

The "options" are f (read from named file rather than stdin), v (verbose mode), and z (run gzip on the archive before processing).

The fact that these options can be written without leading dashes, and all smashed together in a single argument, is legacy silliness for saving a few keystrokes. Don't confuse yourself with it, and don't confuse other people by teaching it to them, instead of teaching them how to actually use the command (which is really not hard at all).

So when I write Tar commands, I like to think along these lines. Instead of "tar zcvf foo.tar.gz", I write "tar -c -zv -f foo.tar.gz". After doing that about 3 times, it all sank in. Nowadays I'm much more intimidated by Git than Tar.

In the version of tar on the machine I'm posting from (GNU tar 1.27.1), this structure is obvious from right there in the man page:

    SYNOPSIS
       Traditional usage
           tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG...]
    
       UNIX-style usage
           tar -A [OPTIONS] ARCHIVE ARCHIVE

           tar -c [-f ARCHIVE] [OPTIONS] [FILE...]

           tar -d [-f ARCHIVE] [OPTIONS] [FILE...]

           tar -t [-f ARCHIVE] [OPTIONS] [MEMBER...]

           tar -r [-f ARCHIVE] [OPTIONS] [FILE...]

           tar -u [-f ARCHIVE] [OPTIONS] [FILE...]

           tar -x [-f ARCHIVE] [OPTIONS] [MEMBER...]
Re:Learn just enough Linux to get things done by gandreani on Thursday November 16, 2017 @12:08PM (#15714377)
Thank you! That was very useful
Re:Learn just enough Linux to get things done by aldanor on Friday November 17, 2017 @07:56AM (#15721589)
Also -j for un-bzip2-ing which comes useful quite often.
Re:Learn just enough Linux to get things done by jcelerier on Thursday November 16, 2017 @01:05PM (#15714915)
You can just do `tar caf` and `tar xaf`. It detects the archive format automatically (and I personnally find it easier to remember: "compress-as-fuck" and "extract-as-fuck").
Re:Learn just enough Linux to get things done by milankragujevic on Thursday November 16, 2017 @11:06PM (#15718810)
wow thanks for that :)
Re:Learn just enough Linux to get things done by reacweb on Thursday November 16, 2017 @10:30AM (#15713398)
Yes. I also suggest to use tar instead of the dangerous cp -r: tar c -C src . | tar x -C dst.

It works over ssh connections (ssh -C for compression) and is a good training of tar syntax.

Re:Learn just enough Linux to get things done by AstralStorm on Thursday November 16, 2017 @01:40PM (#15715274)
It is also quite slow.

For such moves rsync works much better.

Re:Learn just enough Linux to get things done by GlennS on Thursday November 16, 2017 @02:02PM (#15715453)
Over years I've heard a lot of complaints on tar being hard to use, but in real-life I really ever had to use only these two commands: zip and unzip. It's actually quite easy to remember: zip, and unzip.
Re:Learn just enough Linux to get things done by liveoneggs on Thursday November 16, 2017 @10:23AM (#15713309)
add 'tar r' and 'tar u' to your arsenal.
Re:Learn just enough Linux to get things done by emmelaich on Thursday November 16, 2017 @09:54PM (#15718561)
In about 40 years of using Unix I have never used r or u.
Re:Learn just enough Linux to get things done by liveoneggs on Friday November 17, 2017 @12:46PM (#15724141)
both seem fairly important in the 40-years-ago world concerning the 't'(ape) part of tar but okay.

I use them frequently as an "rsync"-ish into the archive file, which I can then use to take point-in-time snapshot/backups.