How to Create a Tar File in Linux

Question: How do I create a tar file from various files or directory?

Answer: If you want to create a single tar archive files from several files or directory, you can use the tar command for this purpose. The simplest way to do this is by using the command in the following fashion:

tar -cvf file_name.tar <path_to_directory>

To give you a quick explanation of the command options:

c – Create a new .tar archive file

v – Verbose mode to show the files being progressed

f – Name of the archive file (can be STDOUT if the filename is replaced by -)

You may think that it is obvious that there will be a file name and thus the option f is really not needed but that’s not the case here. Do keep in mind that commands like tar have been used for decades now. Most of the options these veteran commands use have historical significance as they used to deal with a different type of IT infrastructure.

To create a tar file from several files, use the same command in the following fashion:

Share this:

Other Linux Command Tips

About Abhishek Prakash

I am a software developer by profession and a Linux user by passion. I also co-founded It's FOSS. Linux Quick Tips is my quick notebook where I share quick Linux command tricks, some basic and some advanced.

Comments

Namely digital tape, with which the mt command was used to position the tape — mt erase, mt seek, mt rewind etc.

A useful feature of modern GNU tar is that the output tar file can also be compressed provided that the necessary compression program is installed on the system — the command line option letters being j for bzip2, J for xz, x for gzip, and Z for the ancient compress.

Another options to be aware of is p for preserve for file permissions.