RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

tar

Article Index
1. Name
2. Synopsis
3. Frequently used options
4. Examples

1. Name

tar [man page] - The GNU version of the tar archiving utility

2. Synopsis

tar  [ - ] A --catenate --concatenate | c --create 
| d --diff --compare | --delete | r --append
| t --list | u --update | x --extract --get [ options ]
pathname [ pathname ... ]

3. Frequently used options

-f, --file [HOSTNAME:]F
use archive file or device F (default "-",
meaning stdin/stdout)
-j, --bzip2 filter archive through bzip2,
use to decompress .bz2 files.
-N, --after-date DATE, --newer DATE
only store files newer than DATE
-v, --verbose
verbosely list files processed
-w, --interactive, --confirmation
ask for confirmation for every action
-z, --gzip, --gunzip, --ungzip
filter the archive through gzip

4. Examples

For the sake of simplicity we show linux tar examples without using a tape drive. Many of the tar examples can be translated to use tape drive. For example: Create a archive of /etc/ directory to a file etc.tar

tar -cf etc.tar /etc 

to create a archive to the tape (/dev/st0 ) instead of archive file we can translate this command to:

tar -cf /dev/st0 /etc 

During this tar tutorial we will use "archivewithtar/" directory as sample directory. Here is a content of this sample directory: archive directory with tar
Create an archive to linuxtarfile.tar file of the archivewithtar/ directory:

tar cf linuxtarfile.tar archivewithtar/ 

archive directory with tar to a file
To see what files are being archived by tar command we can use - v ( tar verbose mode ):

tar cf linuxtarfile.tar archivewithtar/ 

tar archive with verbose mode
To instruct tar command to list all files within a archive file we can use command:

tar tf linuxtarfile.tar 

make tar to list all files within an archive
To extract just particular files from a tar archive file we need to replace "c" option with "x". Here we extract archivewithtar/dmesg to a restore/ directory.

tar xvf linuxtarfile.tar archivewithtar/dmesg 

tar - extract just particular file
Extract entire contents of the tar archive linuxtarfile.tar file to restore/ directory:

tar xvf ../linuxtarfile.tar 

Extract entire contents of the tar archive
Linux tar archive command does not use compression by default. Most commonly used compression types with tar command are -z ( gzip ) and -j ( bzip2 ). Create compressed archive of archivewithtar/ with gzip and bzip2:

tar czf linuxtarfile.tar.gz archivewithtar/ tar cjf linuxtarfile.tar.bz2 archivewithtar/ 

Compare the size of all three tar archives files: no compression, gzip and bzip2: create compressed archive with tar
The approach to extract files from compressed tar archive is the same as to extract data from non-compressed tar archive. Here we extract files from gzip compressed tar archive file:

tar xvzf linuxtarfile.tar.gz 

extract compressed archive with tar
Linux tar archive command can create simple incremental or differential backup with -N or --newer option. Let's consider two files in our archivewithtar/ which have different change time:

simple tar incremental or differential backup
Use tar to archive files newer than "7.2.2008 13:54:00" ( make sure to you use correct tar date format !):

tar cvf linuxtarfile.tar --newer  "2008-02-07 13:54:00" archivewithtar/  

simple tar incremental or differential backup newer
Tar command in interactive mode gives us an option which files to extract:

tar xvjwf linuxtarfile.tar.bz2 

interactive tar to extract particular files
Use -p ( --preserve-permissions )tar option to preserve permissions file permission:

tar czfp linuxtarfile.tar.gz archivewithtar/ 

Share this linux post:

Submit tar in Delicious Submit tar in Digg Submit tar in FaceBook Submit tar in Google Bookmarks Submit tar in Stumbleupon Submit tar in Technorati Submit tar in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download