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:
tar -cvf file_name.tar <path_to_file1> <path_to_file2> <path_to_file3>
I hope this quick Linux tip helped you with creating tar archive files in Linux. Bookmark this website or add to your feed reader for more quick Linux tips in future.