FactorPad
Build a Better Process

Linux tar Command Summary with Examples

Linux 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.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux tar, 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 Tip Next

/ factorpad.com / tech / linux-essentials / tar-command.html


An ad-free and cookie-free website.


Examples of the Linux tar Command

Beginner

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

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux tar Command Summary with Examples (3:45)

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.

Common Linux tar Options
-options description
-?, --help, --usage Print help screen and syntax
-f Use file archive
-v Pirnt verbose detailed messages

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, follow and connnect.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / tar-command.html


linux tar command
tar example
tar command
linux tar
tar linux
tar file
tar directory
tar extract
tar options
tar a folder
linux tar directory
tar file linux
extract tar
unzip tar
tar command examples
tar command tutorial
man tar
tar zip file
file compressor
archive file

A newly-updated free resource. Connect and refer a friend today.