Unix/Linux : How to archive and compress entire directory ?
While writing tutorial on how to untar a gzipped tar ball archive with Golang today, I was lost at how to actually create a tar ball archive and compress the tar ball. Maybe I'm just getting too old or could't remember the exact command after such a long time.
Therefore I better write a short tutorial on how to use the tar
command to archive and compress entire directory(and sub-directories).
The simplest command to create a tar ball :
> tar -zcvf tarball.tar.gz /directorytoarchive
Basically the command above is to :
-z Compress archive with gzip format
-c Create archive
-v Verbose mode ( more information)
-f Archive filename to be created
So the parameters should look like this :
> tar -zcvf <archivenametobecreated.tar.gz> <directory to be archived>
Just in case that you only want to create tar ball WITHOUT gzip.
> tar -cvf <archivenametobecreated.tar.gz> <directory to be archived>
// just minus the z
flag
Hope this short tutorial is useful for you.
See also : Unix/Linux : How to open tar.gz file ?
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.2k Golang : Check if integer is power of four example
+14.5k Golang : How to get URL port?
+11.5k Swift : Convert (cast) Float to String
+3.7k Java : Random alphabets, alpha-numeric or numbers only string generator
+13k Golang : Calculate elapsed years or months since a date
+9.7k Random number generation with crypto/rand in Go
+48.5k Golang : Upload file from web browser to server
+19.7k Golang : Archive directory with tar and gzip
+11.3k Golang : Characters limiter example
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+32.3k Golang : Math pow(the power of x^y) example
+14.5k Golang : GUI with Qt and OpenCV to capture image from camera