FactorPad
Faster Learning Tutorials

Linux tar command summary with examples

tar allows you to archive files and directories.
  1. Purpose - Learn what tar is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with tar.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, November 7, 2016
Updated: August 5, 2018
In this tutorial, 73 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / tar command


The Linux tar command

Beginner

Learn to compress and decompress files and directories at the Linux command line.

Video Tutorial

Linux tar command summary with examples (3:45)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our seventy-third word, or command to memorize is tar from our category Files.

tar allows you to archive files and directories.

Recall from the last several videos, we've been seeing ways to compress files and now we'll focus on the main tool Linux uses to create archives of files and directories, with or without compression.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The tar command has over 50 options and the arguments include the output file, in .tar format, then input files or directories. Before the options we input a mode, like c to create, t to list and x to extract, and there are many others. Some modes do require an additional argument.

Like most commands, help is available with double-dash --help. Then after the mode, you tack on an f for files and v for verbose messages. And again, there are many more options here too.

So why is tar an important command? Well, since tar is the default file packaging mechanism for Linux, you need to get comfortable with it. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. First, let's grab that great man page for tar and make a file, video73a.txt then ls -og video73* to confirm.

$ man tar > video73a.txt $ ls -og video73* -rw-r--r-- 1 14920 Nov 7 11:34 video73a.txt

Next, let's get in create tar mode, for files, using -cf, but you could use it without the dash as well, video73.tar, which is the target, and put in there video73a.txt. And we're only using one here to keep it super simple.

$ tar -cf video73.tar video73a.txt

Then an ls -og video73* again.

$ ls -og video73* -rw-r--r-- 1 14920 Nov 7 11:34 video73a.txt -rw-r--r-- 1 48385 Nov 7 11:42 video73.tar

And there it is. Notice how, unlike with our compression commands, it doesn't remove the file, the original? That's different here.

And last, let's use the -t, listing mode, for files with f, like this.

$ tar -tf video73.tar video73a.txt

And see what's inside the tar file.

A Final Tip

Okay now you know how to use tar. And you know the syntax for commands, options and arguments.

One last tip about the tar command. So I'm reluctant to go much deeper with tar in this short time frame, but make note, you can also use compression algorithms we covered, like gzip and bzip2. Something to consider.

Okay, thanks for visiting today. I hope this was a helpful introduction to the tar command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

To be notified of new video content, subscribe to the YouTube Channel here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the zip command, hit Back.
  • To learn a neat tool for setting up remote backups with the rsync command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / tar command



 
 
Keywords:
linux tar command
tar linux
tar example
unzip tar
compress files linux
compress directories linux
decompress files linux
decompress directories linux
open tar
tar file
extract tar
untar tar
tar directory
tar options
tar command
file archive
man tar
archive file
file compressor
tar zip file
tar command tutorial
tar command examples