Zip and unzip with command using terminal

There are various package that does this job but we will talk about `tar` that simply zip and uzip files and folders. This small article will show you how to zip and unzip with command using terminal.

To zip files

tar -czvf zip_file_name.tar.gz -C ./dist .
  • 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.

To unzip files

tar -xvzf uploadable.tar.gz -C ./.

To extract into a custom folder, add the -C option with a folder name of your choice. As above code it represent current directory with all file denote as dot ( . )

At some point tar was upgraded to auto-decompress. So you can also remove v and z.

tar xf uploadable.tar.gz

Note the lack of hyphen for the command flags. This is because most versions of tar allow both gnu and bsd style options (simplistically, gnu requires a hyphen, bsd doesn’t).

credit link unzip file

Credit link 2 Zip file and folder

Leave a Reply

Your email address will not be published. Required fields are marked *