Skip to content

Instantly share code, notes, and snippets.

@mcortes19
Last active August 17, 2017 16:52
Show Gist options
  • Save mcortes19/b56cf31326eb7a97af47c991587bcbd8 to your computer and use it in GitHub Desktop.
Save mcortes19/b56cf31326eb7a97af47c991587bcbd8 to your computer and use it in GitHub Desktop.
Ways to compress and uncompress files and foldes by terminal commands

COMPRESS AND UNCOMPRESS FILES AND FOLDERS BY TERMINAL

Files with extension GZ and ZIP

ZIP - CROSS PLATFORM

  • To compress

      zip -r <archive_name.zip> <folder/files_to_compress>
    
  • Compress without MACOSX or .Filename and .ds store files, use the -X option in the command so

      zip -r -X <archive_name.zip> <folder/files_to_compress>
    
  • To extract

      unzip <archive_name.zip>
    

TAR.GZ – CROSS PLATFORM

NOTE: If you come from a Windows background, you may be familiar with the zip and rar formats. These are archives of multiple files compressed together.

In Unix and Unix-like systems (like Ubuntu), archiving and compression are separate.

tar puts multiple files into a single (tar) file.

gzip compresses one file (only).

reference

  • To compress

      tar -zcvf <archive_name.tar.gz> <folder/files_to_compress>
    
  • To extract

      tar -zxvf <archive_name.tar.gz>
    
  • To extract

      tar -zxvf <archive_name.tar.gz> -C </Path/To/Extract>
    
  • c = Create

  • x = Extract

  • v = Verbose mode

  • p = Preserving files and directory permissions.

  • z = This will tell tar that compress the files further to reduce the size of tar file.

  • f = It allows tar to get file name.

  • C = Extract in different directory.

TAR.BZ2 – CROSS PLATFORM

  • To compress

      tar -jcvf <archive_name.tar.bz2> <folder_to_compress>
    
  • To extract

      tar -jxvf <archive_name.tar.bz2>
    

GZ

  • To compress

      gzip <folder_to_compress>
    
  • To extract

      gunzip <archivename.gz>
      gzip -d <archivename.gz>
    

Reference

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