How To Compress A Folder On Linux

In Linux, Tutorial 823 views

On Linux, gzip is unable to compress a folder, it used to compress a single file only. To compress a folder, you should use tar + gzip, which is tar -z.

Note

$ tar --help
  -z, -j, -J, --lzma  Compress archive with gzip/bzip2/xz/lzma

For example,

tar -zcvf outputFileName folderToCompress

1. Tar + Gzip a folder

Example to gzip a folder named “newrelic”, and also all the files within that folder, into a single compressed filenewrelic.tar.gz

$ tar -zcvf newrelic.tar.gz newrelic/
 
a newrelic
a newrelic/.DS_Store
a newrelic/CHANGELOG
a newrelic/extension-example.xml
a newrelic/extension.xsd
a newrelic/LICENSE
a newrelic/newrelic-api-sources.jar
a newrelic/newrelic-api.jar
a newrelic/newrelic.jar
a newrelic/newrelic.yml
a newrelic/nrcerts
a newrelic/README.txt
 
$ ls -lsa
 
     0 drwxr-xr-x  13 mkyong  staff        442 Jan 24 21:40 newrelic
 11072 -rw-r--r--   1 mkyong  staff    5667938 Jul 23 15:44 newrelic.tar.gz

List the contents of newrelic.tar.gz

$ tar -tf newrelic.tar.gz
newrelic/
newrelic/._.DS_Store
newrelic/.DS_Store
newrelic/._CHANGELOG
newrelic/CHANGELOG
newrelic/._extension-example.xml
newrelic/extension-example.xml
newrelic/._extension.xsd
newrelic/extension.xsd
newrelic/._LICENSE
newrelic/LICENSE
newrelic/._newrelic-api-sources.jar
newrelic/newrelic-api-sources.jar
newrelic/._newrelic-api.jar
newrelic/newrelic-api.jar
newrelic/._newrelic.jar
newrelic/newrelic.jar
newrelic/._newrelic.yml
newrelic/newrelic.yml
newrelic/._nrcerts
newrelic/nrcerts
newrelic/._README.txt
newrelic/README.txt
source : mkyoung.com
or you can use this command :
zip -r compressed_filename.zip foldername

Related Search

Tags: #compress #folder #gzip #linux #tar #zip

Install Pi-Hole DNS Blokir Iklan dan Tracker
Install Pi-Hole DNS Blokir Iklan dan Tracker
Pi-Hole merupakan salah satu pelindung user internet
Migrasi VPS Panel dari Tuxlite ke VestaCP
Migrasi VPS Panel dari Tuxlite ke VestaCP
Setelah sekian lama menggunakan Tuxlite akhirnya diputuskan
Cara Cepat Root Unlock STB ZTE B760H Tanpa Bongkar
Cara Cepat Root Unlock STB ZTE B760H Tanpa Bongkar
Mungkin beberapa ada yang pernah berlangganan Indihome
Upgrade PHP 5.6 ke PHP 7.0 Nginx Debian Jessie
Upgrade PHP 5.6 ke PHP 7.0 Nginx Debian Jessie
Sebetulnya sudah agak lama warning untuk upgrade

Top