100 Useful Command-Line Utilities

by Oliver; 2014

45. tar

tar rolls, or glues, an entire directory structure into a single file.

Tar a directory named dir into a tarball called dir.tar:
$ tar -cvf dir.tar dir
(The original dir remains) The options I'm using are -c for "create a new archive containing the specified items"; -f for "write the archive to the specified file"; and -v for verbose.

To untar, use the -x flag, which stands for extract:
$ tar -xvf dir.tar
Tar and zip a directory dir into a zipped tarball dir.tar.gz:
$ tar -zcvf dir.tar.gz dir
Extract plus unzip:
$ tar -zxvf dir.tar.gz

<PREV   NEXT>