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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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/Enable Numa for Virtual Machine (XEN based)
  2. How to work with multiple java versions under Linux
  3. How to Change Time Interval to Fall Back to Secondary DNS Server in CentOS/RHEL
  4. CentOS / RHEL : How to find Logical volumes (LVs) contained in Physical Volume (PVs) in LVM
  5. Understanding OpenSSH Configuration Files
  6. Anonymous User Fails to Upload File to VSFTP Server
  7. CentOS / RHEL 6 : How to add/remove additional IP addresses to a network interface
  8. How to configure Partitioned Block Devices (Non-ASMLIB) And Assign Them To ASM
  9. CentOS / RHEL 7 : Shutting Down, Suspending, or Rebooting Commands (systemctl)
  10. Repairing filesystem issues at Boot in CentOS/RHEL 7 and 8

You May Also Like

Primary Sidebar

Recent Posts

  • Oracle Database – Configuring Secure Application Roles
  • Extend rule sets by using factors in Oracle Database Vault
  • What are Command Rules in oracle Database
  • Using Rule Sets in Oracle Database Vault
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary