← All cheatsheets

tar Cheatsheet

A tar cheatsheet for the flags you always forget: create, extract, and list archives, plus the gzip/bzip2/xz compression variants — copy-ready with editable file names.

Explain a command

Create

  • Create a .tar.gz archive
    tar -czf .tar.gz
  • Create an uncompressed .tar
    tar -cf .tar
  • Create a .tar.xz (smaller, slower)
    tar -cJf .tar.xz
  • Create, excluding a pattern
    tar --exclude= -czf .tar.gz

Extract

  • Extract a .tar.gz here
    tar -xzf .tar.gz
  • Extract any tar (auto-detect compression)
    tar -xf
  • Extract into a specific directory
    tar -xzf .tar.gz -C
  • Extract a single file/dir
    tar -xzf .tar.gz

List & inspect

  • List archive contents
    tar -tzf .tar.gz
  • List with sizes and permissions
    tar -tvzf .tar.gz

Variants

  • Create a .tar.bz2
    tar -cjf .tar.bz2
  • Create and print each file added
    tar -czvf .tar.gz

12 commands. Copy-ready with editable placeholders — everything runs in your browser, nothing is sent to a server.