Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the tar command. It’s used to create (and extract contents from) file archives – groups of files that are merged into single files to preserve them as a group or move them easily to some other location. The name “tar” stands for “tape archive” though “tape” is rarely part of the equation anymore.
As an example, say I wanted to move all of my PDFs from one system to another. Instead of moving them one at a time, I could use tar to create an archive and then move the archive to the other system with a single command. Here are the commands I might use:
The “c” means “create”, the “z” means I want the archive compressed, the “v” means “verbose” (show me the files being added) and the “f” stands for “file” (the file I’m going to create). The PDFs.tgz file is the one created and will contain all files with the .pdf extension.
Once a tar file is moved to another system, I could use a command like one of these to extract the contents:
The “x” means “extract”. The file extensions indicate whether the file is compressed or not.
If I want to extract only a single file from the archive, I could do this:
You can also compress tar files using other commands – sometimes with a better compression ratio. The tar command uses gzip to do the compression.
That’s your Linux tip for the tar command.
If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.