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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. How to Disable VNC Server from Xinetd in CentOS/RHEL 7
  2. How to Connect Remote Host Using the ssh Command
  3. btrbk Command Examples in Linux
  4. Beginners Guide to SELinux
  5. lsmod: command not found
  6. Understanding rsyslog Actions
  7. ss: command not found
  8. cgcreate: command not found
  9. “Failed to Synchronize Cache For Repo ‘repo_name’, Ignoring This Repo” – CentOS/RHEL 8 error
  10. How to Extend the Last Existing Filesystem Partition with Parted

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright