Use tar and gz to create archive in Ubuntu Terminal

13,834

Solution 1

You either need to redirect that output to your tarball name as in:

tar -c abc tt zz > tarball.tar

(Careful, that will overwrite tarball.tar if it's already there) or you need to use the -f flag for tar and specify a filename as in:

tar -cf tarball.tar abc tt zz

Solution 2

You can use this command

 tar -cvzf tarname.tar.gz a b c

eg:

x@x:/tmp/aas$ touch a b c
x@x:/tmp/aas$ ls
a  b  c
x@x:/tmp/aas$ tar cvzf tarname.tar.gz a b c
a
b
c
x@x:/tmp/aas$ ls
a  b  c  tarname.tar.gz
x@x:/tmp/aas$ rm a b c
x@x:/tmp/aas$ ls
tarname.tar.gz
x@x:/tmp/aas$ gunzip -c tarname.tar.gz | tar xvf -
a
b
c
x@x:/tmp/aas$ ls
a  b  c  tarname.tar.gz
x@x:/tmp/aas$ 
Share:
13,834

Related videos on Youtube

radu florescu
Author by

radu florescu

Full Stack Web Developer and AI geek. View expressed are my own, not my employers. Github LinkedIn

Updated on September 18, 2022

Comments

  • radu florescu
    radu florescu over 1 year

    I want to archive 3 folders, given their names in Ubuntu command prompt.
    When I use tar -c abc tt zz -> it will do nothing.

  • radu florescu
    radu florescu over 12 years
    how about the use of gz?
  • radu florescu
    radu florescu over 12 years
    how about the use of gz?
  • daya
    daya over 12 years
    this will tar and gzip it in a single command. If you wish you can do it seperately as well
  • revetinja
    revetinja over 12 years
    if you add the -z flag to the tar command it will tell it to use gzip compression (e.g. tar -czf tarball.tar.gz abc tt zz), -j will use bzip2 (e.g. tar -cjf tarball.tar.bz2 abc tt zz). The way that tar handles it's output is the same whether or not compression is used. Without the -f it goes to stdout.
  • Justin
    Justin almost 8 years
    The link is broken