Jump to content

Linux Archives for beginners/ tar basics

Herr.Hoefkens

816 views

 

with the comming of new linux users , and the existance of many chatrooms and more importantly many use `tldr` wich is much faster and easier to get what you need from then using the man pages.

even moreso when many distros dont even set up the defaults so the manpagers are colored and are just a big sea of white text . i see many who dont actually know how to use the tar command and stuff like:

help me im doing :
	tar fxcz somefile.tar.bz2 
and it gives an error

help me im doing

so here are the tar basics:

 

tar doesnt require short form options to be indicated by a - , but allows it so 'tar -xvzf' is the same as 'tar xvzf' or as 'tar -x -v -z -f'

  • [short] [-short] [--longform]
  • f  -f --file f              |     indicates that what follows is a filename (either for creation or extracting from ).
    • -> this is usually used to change the order of things , since tar can take more arguments when creating an archive f is used so the archive name can be put first in that series  of arguments. for extraction tar reads from stdin by default
      cat [filename] | tar xv 
      # is equivalent to
      tar -xvf [filename]

       

  • x  -x  --extract     |     extract
  • c -c  --create      |     creating 
  • v -v --verbose    |     show everything your doing for archives with thousands of little files this wil slow the extraction process quite significantly. but on archives with a few big files it shows you that the process doesnt hang and is still going.
  • C -C --directory |    Captal C is used to change directories
    • this allows tar to look for [file] in the current directory , while extracting it in the [dir] directory
      tar xvf [file] -C [dir] 
      # extracts ./[file] into ./[dir]
      #not the same as
      tar xvC [dir] -f [file]
      # extracts ./[dir]/[file] into ./[dir]
      
    • image.png
  • J --xz             | xz
    • -> if your archive is xz compressed or you want to create one using xz compression (archive ending in .xz)
  • Z  --gzip         | gzip 
    • -> !! (archive ending in .gz)
  • j                     | bzip2
    • -> !! (archive ending in .bzip2)
  • --strip-components      | strips components (usually directories but seen as [archive:./dir/nesteddir/file] wich takes a number following it --strip-components 1
    • -> when you archive a folder and extract it again the folder will be there again but if you want just the files in the folder not the folder itself , this is what you need to do that as it will extract all files at the 2nd level of the archive(we stripped the first)
    • image.png

0 Comments

There are no comments to display.

×