So you want to compress a directory. Here’s how you make a tar file, also known as a “tarball,” from the command line. What follows assumes you already have a basic familiarity with how to navigate the via the terminal.
First, change your current working directory to the parent directory of the folder you want to archive. In other words, if you want to make a tarball of a directory whose pathname is /home/username/Documents/computing/linux/ , you would use the following command:
Second, select a name for the tarball that ends in .tgz . For example, you could call the tarball for the directory above linux.tgz
Third, create the tarball with this command (here I continue with the same example as above):
tar -cvzf linux.tgz linux
What does the command above mean and do?
-c tells tar to create an archive. v makes it display the names of of the files as it processes them. z is to compress the file and f tells tar to use the next name in the command (in this example, linux.tgz for the tarball being created. The final argument in the command is the name of directory (folder) to be saved and compressed.
Hope this helps!