Skip to content

Instantly share code, notes, and snippets.

@haskaalo
Last active February 22, 2024 09:22
Star You must be signed in to star a gist
Save haskaalo/68c0ea38e0abc3d4081db6e9446e8253 to your computer and use it in GitHub Desktop.
Tar usage / Tar Cheat Sheet

Tar Usage / Cheat Sheet

Compress a file or directory

e.g: 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.

Extract an Archive

e.g: 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.
@MiCurry
Copy link

MiCurry commented Oct 9, 2018

Thank you 👍

@worp1900
Copy link

Thanks!

@Blackrobe
Copy link

Blackrobe commented Jun 27, 2019

List files in an archive:

tar -tzf name-of-archive.tar.gz

t: list the contents of an archive
and because it's compressed we also need the z option.

More verbose listing can be done by adding v option:

tar -tzvf name-of-archive.tar.gz

the option adds details you normally see as if you run ls -l inside the archive.

@ikhwan6546
Copy link

Mati la nakkk

@thattimc
Copy link

thattimc commented Jun 5, 2020

Thank you

@ytdlder
Copy link

ytdlder commented Aug 10, 2020

Hope nobody minds if I add this, but here's the command for multithreaded compression (needs 'pigz' installed of course):
tar --use-compress-program=pigz -cf <file.tar.gz> <path-or-file>
or short:
tar -I pigz -cf <file.tar.gz> <path-or-file>

@shahcker
Copy link

What would a tar command look like that needs to create an archive but exclude a folder in the directory?

@mrmartymac
Copy link

Thank you!

@nicolarc96
Copy link

Thanks !

@0x07CB
Copy link

0x07CB commented Feb 6, 2023

Trust me, I tell with hope and my broken heart: next I complete your works, probably with other identity, probably in long time after this declaration, you have made an good short markdown gist document.
I respect you for that, thank you.
I have start last weeks an new and “great work”, I tell no more I keep hidden all tech parts of the most big and hard working results… but my goal is to contribute for an new free world, an world with technology from OpenSource very more in advance than now… (gnu/linux by e.g. is better than multi-nationals with economic-monopol, but all people can’t easily use it, adapt to this and understand without feel fear of unknown…).
For now I learn and train me to made my prototypes of free better tech unpublished (sorry for now) more easy to use, my grandma and my uncle, my dad and at term if I success an great part of my family can be future linux users… and in this epoch, made economic tech for change things to great… I feel that possible now…
I don’t use android, I don’t use iOS.
And an day I hack myself by my way my iPad, grey hat I am but dark the industry do face to me, and I can’t agree in my life to do nothing.

Probably I recall you back, if possible.
I have take time to write, I have need to tell all this things.
Because I love my community, your are all very good, never stop.
🖖🏻🇫🇷

TTYL ! 😎

@ericosg
Copy link

ericosg commented Mar 15, 2023

Trust me, I tell with hope and my broken heart: next I complete your works, probably with other identity, probably in long time after this declaration, you have made an good short markdown gist document. I respect you for that, thank you. I have start last weeks an new and “great work”, I tell no more I keep hidden all tech parts of the most big and hard working results… but my goal is to contribute for an new free world, an world with technology from OpenSource very more in advance than now… (gnu/linux by e.g. is better than multi-nationals with economic-monopol, but all people can’t easily use it, adapt to this and understand without feel fear of unknown…). For now I learn and train me to made my prototypes of free better tech unpublished (sorry for now) more easy to use, my grandma and my uncle, my dad and at term if I success an great part of my family can be future linux users… and in this epoch, made economic tech for change things to great… I feel that possible now… I don’t use android, I don’t use iOS. And an day I hack myself by my way my iPad, grey hat I am but dark the industry do face to me, and I can’t agree in my life to do nothing.

Probably I recall you back, if possible. I have take time to write, I have need to tell all this things. Because I love my community, your are all very good, never stop. 🖖🏻🇫🇷

TTYL ! 😎

wait wut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment