Category: Advanced (Command Line) • Est. reading time: 3 minutes
The tar command bundles many files and folders into a single archive, and it can compress them at the same time. On a server, it is the go-to tool for backups and for moving a whole folder in one piece. Here are the three commands you will actually use.
Create an Archive
tar -czvf backup.tar.gz /path/to/folder
This creates a compressed archive called backup.tar.gz from the folder you name. The letters mean: c create, z compress with gzip, v show progress, f the filename that follows.
Extract an Archive
tar -xzvf backup.tar.gz
Same letters, except x means extract. This unpacks everything into your current folder, so move into the right directory first.
Peek Inside Without Extracting
tar -tzvf backup.tar.gz
The t lists the contents so you can see what is in an archive before you unpack it.
Handy habit: tar a folder before you make risky changes to it. If something goes sideways, you extract the archive and you are back where you started.
Managing your own server and want a second set of hands? Reach us at support@allydrez.com or 1-321-209-2004.