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
+18.7k Golang : Iterating Elements Over A List
+16.3k Golang : Loop each day of the current month example
+12.5k Golang : Arithmetic operation with numerical slices or arrays example
+9.9k Golang : Check if user agent is a robot or crawler example
+6.7k Golang : Skip or discard items of non-interest when iterating example
+6.8k Golang : Join lines with certain suffix symbol example
+6.6k Elasticsearch : Shutdown a local node
+30.6k Golang : Remove characters from string example
+9.4k Golang : Create unique title slugs example
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+15.9k Golang : Get file permission
+40.5k Golang : Convert to io.ReadSeeker type