Using tar and gzip to Compress Files and Directories

Create and Compress and Archive

Archive a group of files:
tar -czvf archive.tar.gz file1 file2 file3
Archive an entire directory:
tar -czvf archive.tar.gz directory/

Extract a Compressed Archive

tar -xzvf archive.tar.gz

List the Contents of a Compressed Archive

tar -tzvf archive.tar.gz

Common tar Switches

  • -c create a new archive
  • -x extract files from an archive
  • -t list the contents of an archive
  • -z filter the archive through gzip
  • -v verbosely list files processed
  • -f filename of the archive (filename must always immediately follow)

Leave a Reply