• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to use tar command under Linux

by admin

The tar (tape archiver) tool is the most commonly used application for data backups on Linux systems. It archives files in a special format, either directly on a backup media (such as tape) or to an archive file in the file system.

The tar Command

The tar command stores, lists, or extracts files in an archive.

$ tar functions archivefile filenames

The output of using a tar command is a tar file. The default output location for a tar file in Linux is the stdout.

The tar Command Options

The table describes some of the commonly used tar command options. For a detailed explanation of the tar command and its options, read the tar man page.

Options Description
c Creates a new tar file
t Lists the table of contents of the tar file
x Lists the table of contents of the tar file
f Specifies the archive file or tape device.
v Specifies the archive file or tape device.
h Follows symbolic links as standard files or directories
z Follows symbolic links as standard files or directories
j Compresses and extracts files and directories using bzip

Creating a tar Archive

You can use the tar command to create an archive file containing multiple files or directories onto a disk or file. The following example shows you how to archive your home directory onto a disk.

$ tar cvf user_home.tar /home/user
/home/user/
/home/user/.bash_logout
/home/user/.bash_profile
/home/user/.bashrc
...

The following example shows you how to archive multiple files into an archive file called test.tar.

# tar cvf test.tar test test1 test2 
test
test1
test2

Viewing a tar Archive

You can view the names of all the files that have been written directly to a disk or file archive. To view the content of the test.tar archive file, enter the following command:

# tar tf test.tar 
test
test1
test2

Extracting a tar Archive

You can retrieve or extract the contents of an archive that was written directly to a disk device or to a file. To extract files from the test.tar archive file, enter the following command:

# tar xvf test.tar 
test
test1
test2
How to use compress, zip, gzip commands under Linux

Filed Under: Linux

Some more articles you might also be interested in …

  1. blkid Command Examples in Linux
  2. eva: Simple calculator REPL, similar to bc, with syntax highlighting and persistent history
  3. vgcreate: command not found
  4. mkinitrd: command not found
  5. runcon: command not found
  6. “git submodule” Command Examples
  7. espanso: Cross-platform Text Expander written in Rust
  8. CentOS / RHEL : How to find free space in a Volume Group in LVM
  9. rmmod Command Examples in Linux
  10. column: Format standard input or a file into multiple columns

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright