Skip to content

Instantly share code, notes, and snippets.

@faesin
Forked from haskaalo/tarcheatsheet.md
Last active April 30, 2021 16:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save faesin/917747490938fb4540f84eda6e831f35 to your computer and use it in GitHub Desktop.
Save faesin/917747490938fb4540f84eda6e831f35 to your computer and use it in GitHub Desktop.
Tar usage / Tar Cheat Sheet

Tar Usage / Cheat Sheet

Compress a file or directory

ex: tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -v: makes tar talk a lot. Verbose output shows you all the files being archived and much.
  • -f: Allows you to specify the filename of the archive.

Excluding a directory

ex: tar -czvf name-of-archive.tar.gz /path/to/dir-or-file --exclude=/path/to/dir-or-file/exclude1 --exclude=/path/to/dir-or-file/.config

Exclude takes a patern, not necessarily file names or paths. So doing something like --exclude=*.png would exclude all png-type files to be compressed.

Extract an Archive

ex: tar -xvzf name-of-archive.tar.gz

  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • z: tells tar to decompress the archive using gzip
  • x: tar can collect files or extract them. x does the latter.
  • v: makes tar talk a lot. Verbose output shows you all the files being extracted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment