The tar cheatsheet and how to never forget




tar, A GNU project which we happened to stumble upon atleast once, and it is never easy understanding the flags to use in order to compress or extract files, so in this short blog post, I am going to give you a list of basic tar functions and their flags and a good way of remembering them. I want to thank an anonymous dev.to user who came up with this idea ‘cause honestly I think it is a nice way. So without further a do, lets dive in and Warning - PG 13 content ahead !

Extracting

extracting using tar is something we would end up doing using tar, and to do that we use the following code

tar -xzvf name-of-archive.tar.gz
  • -f allows you to mention path/file name
  • -v means lot of processing is shown step by step
  • -z tells tar to decompress the file using gzip
  • -x extracts files

How to remember it?

tar Xtract Zhe Vucking File filename.tar.gz

May not be the best way but does get the job done

Compressing

tar lets you compress files or a directory in a tar.gz file. The flags for compressing are quite similar to that of extracting.

tar -czvf name-of-archive.tar.gz
  • -f allows you to mention path/file name
  • -v means lot of processing is shown step by step
  • -z tells tar to compress the file using gzip
  • -c create an archive

How do you remember? This shouldn’t be hard to figure out, once you know the first one

So the next time you ever see a tar.gz file, you won’t have to worry about how to extract, ‘cause you will have it, at the back of your head

Happy compressing and extracting !

Courtesy - dev.to

- Jayakrishna Sahit