Tar Notes

tar stands for tape archive and can be used to make a big file filled with many smaller files which can then be easily transported across directories, mahcines or networks. Cool, huh?

Usage / Syntax

command [-options] /location/of/new/file.tar /files/to/archive


tar -cvf /scratch/myfile_20030617.tar /scratch/mydir/results/stat/*

Popular options and their significance

  -c = create
  -f = read to/from the named file (instead of the device /tape)
  -t = list contents of .tar file
  -r = append to a .tar file
  -v = verbose (tells you everything its doing)
  -x = extract contents of .tar file 
  -z = compress files (not so useful for minc files)

To extract files from your file

tar -xf myfile_20030617.tar
Note that a path name beginning with a forward slash is an absolute path name, e.g.: /scratch/mydir whereas a path name with no forward slash at the beginning is a relative path name. Thus, if you are in directory /scratch/mydir and want to tar a bunch of files in /scratch/mydir/subdir, you may use relative path names, eg:

tar -cf /scratch/myfile_blah.tar subdir/*

To select files for the tar file using find

tar -cvf ps.tar `find /path/name/here -name '*.ps*' -print` gzip ps.tar

Be diligent with use of backquotes (`) and forward quotes (')!

Ave to Hans Petter Langtangen, Dept. of Informatics, University of Oslo for posting this tip on his website.

To move tar file from one location to another

from a machine outside BIC
scp me@machine.mni.mcgill.ca:/scratch/myfile_20030617.tar /local/path/

from a machine inside BIC:

scp /scratch/myfile_20030617.tar me@remote.machine.ca:/local/path/