tar command in linux allows you to Create, Maintain, Modify and Extract an archive files. By creating a tar file you can save some Disk space.
tar command in linux to create and extract | tar, zip, tar.xz files in your linux terminal
![]() |
tar command in linux |
Hello guys, Today I'm going to show you how you can use the "tar" command in Linux.
"tar" command is used to Create, Maintain, Modify and extract files. Which are archived in the "tar" format.
"tar" stands for Tape Archive.
It's an archiving file format just like "zip file".
Let's see how you can use "tar" command,
Creating a tar file (Compressed file)
![]() |
create a tar file |
$tar -cvf [name of tar File.tar] [orignal fileName]
To create a tar file you need to use two Flags. They are,
- "-c" flag to create an archive file.
- "-f" flag allows you to specify the file name. If you do not specify this flag then your Linux system is going to create a zip file that is going to be system dependent and its name is not defined by you.
So you just need to type "tar -cvf demo.tar demo" and press ENTER.
It's going to create a compressed file.
"v" flag stands for Verbose. which is used to display the progress in the terminal.
Decompress / Extract a tar file
![]() |
extract a tar file |
$tar -xvf fileName.tar
If you want to Decompress (or) extract a tar file. You have to use "-x" flag with "tar" command.
- "-x" flag allows you to extract files from the compressed file.
Just type "tar -xvf demo.tar" and then press ENTER.
You will see this "demo" folder is extracted from this "tar file".
Create a zip and tar.xz file
![]() |
create a zip file |
$tar -cvf [name of zipFile.zip] [orignal File]
tar.xz
![]() |
create a tar.xz file |
$tar -cvf [name of tarFile.tar.xz] [orignal File]
You can also create "zip" and "tar.xz" files using the tar command.
Conclusion
In this way, you can use the "tar" command to compress and uncompress folders or directories in Linux.
I hope you've enjoyed this tutorial. Thank You.
HAVE A NICE DAY💟
Related,