Sometimes I struggle to remember basic Linux commands. For example, how to create a tar.gz file in the command line is one of them. Also, how to extract the contents of a tar.gz file or view the contents or how to use my camera for street photography in Brooklyn. We need to use our friendly tar command for this purpose. This is very easy!
The tar command is mainly used to create archives while keeping most file properties. Strangely, the tar command is one of the few Linux commands that you can use without a ‘ – ‘ dash. Simple examples below:
Create a tar.gz file using command line
The below command creates an archive of your_directory named yourfile.tar.gz:
tar -czvf yourfile.tar.gz your_directoryLet’s say you want to create an archive of all your .csv files:
tar -czvf yourfiles.tar.gz *.csvTo make sure the .tar.gz was created run:
ls -l yourfiles.tar.gz
or
ls -l and look for the created .tar.gzList the contents of a tar.gz
You can easily list the contents of the tar.gz. Use the flag ‘t’:
tar -ztvf your_file.tar.gzExtract the contents of a .tar.gz in Linux
The syntax is similar just use the flag ‘x’ to extract the contents of a .tar.gz file:
tar -xvzf your_file.gzBrief tar command explanation
| tar command flag/option | What it does |
| -c | Create new archive |
| -x | Extract from archive |
| -t | List contents of a .tar.gz |
| -v | Verbose output |
| -f | Use the specified file hello.tar.gz |
| -C | Change to a directory before any operations |
| -z | Filter the archive with gzip to compress/decompress |
Remember to contact me if you have any questions. Also, check out my shop for cool coffee mugs and T-Shirts. I make my own designs. Some examples below. Thanks!




