Linux Tar Command
How Can I Do Archiving With Tar?
The tar CommandThe tar (tape archive) command bundles a bunch of files together and creates an archive (commonly called a tar file or tarball) on a tape, disk drive, or floppy disk. The original files are not deleted after being copied to the tar file. To create an archive using tar, use a command like this, which bundles all the files in the current directory that end with .doc into the alldocs.tar file:
tar cvf alldocs.tar *.doc
Here's a second example, which creates a tar file named panda.tar containing all the files from the panda directory (and any of its subdirectories):
tar cvf panda.tar panda/
In these examples, the c, v, and f flags mean create a new archive, be verbose (list files being archived), and write the archive to a file. You can also create tar files on tape drives or floppy disks, like this:
tar cvfM /dev/fd0 panda Archive the files in the panda directory to floppy disk(s).
tar cvf /dev/rmt0 panda Archive the files in the panda directory to the tape drive.
The /dev/fd0 entry is Linux-ese for "floppy drive zero" (your A drive under DOS), and /dev/rmt0 means "removable media tape zero," or your primary tape drive. The M flag means use multiple floppy disks--when one disk is full, tar prompts you to insert another.
To automatically compress the tar file as it is being created, add the z flag, like this:
tar cvzf alldocs.tar.gz *.doc
In this example, I added the .gz suffix to the archive file name, because the z flag tells tar to use the same compression as the gzip command.
To list the contents of a tar file, use the t (type) flag in a command, like this:
tar tvf alldocs.tar List all files in alldocs.tar.
To extract the contents of a tar file, use the x (extract) flag in a command, like this:
tar xvf panda.tar Extract files from panda.tar.
This will copy all the files from the panda.tar file into the current directory. When a tar file is created, it can bundle up all the files in a directory, as well as any subdirectories and the files in them. So when you're extracting a tar file, keep in mind that you might end up with some new subdirectories in the current directory.
We've used several different flags in the sample tar commands so far. Here's a list of the most common flags:
c Create a new archive.
t List the contents of an archive.
x Extract the contents of an archive.
f The archive file name is given on the command line (required
whenever the tar output is going to a file)
M The archive can span multiple floppies.
v Print verbose output (list file names as they are processed).
u Add files to the archive if
they are newer than the copy in the tar file.
z Compress or decompress files automatically.
For more information on the tar command, see the tar manual.
Previous Lesson: Linux File Compression
Next Lesson: Compression With Gzip
Comments - most recent first
(Please feel free to answer questions posted by others!)
beartils
becayuse i am woking on the project of log module which is totaly based on the shell programming..
thank you and regards
mayur saswade
In spite of the cloudy day time if the bad weather when, they were adament around the journey after this, the last 90 kms aside, the trail needed 8 . 5 several hours. They had been combined with his / her associate Wu Lin along with the various other a The german language. Just before that, they begin via Yunnan Shangri-La, entirely over the Yangtze River using, riding 4,500 kms throughout Sixty six nights.
German born participant present his or her travel records for that Water Lin, the present 4,Thousand kilometers experience four to five instances a year in just his or her journey soon enough.
thanx for such a good technique to teach us.
I am big fan dr.
Thank u very much
I find your website really useful, but I'd like to know why when I click 'return to index' it goes to the comment sections?
Very objective and didactic!!!
Thanks and regards
Can anyone who can help me
Thankx Bob ...
You are simply the best. Being a novice Linux user, these pages are a great help!
Rudi
1). Unzip the *.tar.gz file by the command --- gunzip file.tar.gz
which will create a file.tar file
2).Now extract all files by the following command
tar -zxf file.tar
According to the man page ("man tar"), the -z option compresses or decompresses the file with gzip (mentioned above), whereas the -j option uses bzip instead. I think bzip files are traditionally given the ending "bz2", whereas gzip files are given the ending "gz", so that it's easy to tell what compression program was used. I also vaguely recall that bzip usually creates a slightly smaller file (~10%?), but takes longer - sometimes noticeably longer. As for the "joomla" directory (I don't know what that is), could you just use "tar -cvzf joomla.tgz /path/to/joomla_directory/" to create a tarballed file, transfer it to the directory where you want the new directory to be, then untarball it with "tar -xvzf joomla.tgz"? Hope that helps.
I want to know why the '-' is using with the tar cammand
Eg:- tar -cvf/dev/st0 tata.sql
Pls help me
Thanking u
hai sir good eveing please suggest me that how i take backup of data and tar and cpio and dd and dump back up what is the difference between commands.
i am b.tech student and was just learning the basics of unix actually i learnt that there is a difference between tar and other commands what does it meant by?
http://forums.gentoo.org/viewtopic-p-6301733.html
I am great fan of low fat Linux. I often refer to it and so far it has never really disappointed me :)
I have one doubt though. I get
tar: ./POS: Cannot utime: Operation not permitted
error quite frequently while doing tar xvf filename.
Can it be safely ignored ? What does it mean any ways.
Regards,
Aditya
please suggest me that how i take backup of data??
please help me
2. tar file extact command (linux)
please suggest me that how i take backup of data??
please help me
I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But
don't ask me to send what you already have. :-) NO SPAM! If you post garbage, it will be deleted, and you will be banned.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

