LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-17-2009, 01:46 AM   #1
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Rep: Reputation: 0
tar command help


I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.

Last edited by caponewgp; 09-17-2009 at 01:47 AM.
 
Old 09-17-2009, 02:09 AM   #2
themanwhowas
Member
 
Registered: Nov 2005
Distribution: CentOS 5, Fedora 23
Posts: 216

Rep: Reputation: 29
it would create an archive called backup1.txt which would contain 3 files (backup2.txt, backup3.txt and backup4.txt)
 
Old 09-17-2009, 02:12 AM   #3
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by caponewgp View Post
I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file
Yes, but this is a mistake -- the archive is given the name of the first file in the list (and that file's contents are lost). You don't want to do this.

Also, use the standard syntax -- prefix a "-" to the option list:

Code:
$ tar -cvf archive_name.tar *
Quote:
Originally Posted by caponewgp View Post
However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.
So you aren't giving TAR a filename and you wonder what TAR will do without any guidance? Have you considered solving the problem by giving TAR a filename? Have you considered performing an experiment to test your assumptions?

You must give TAR either a filename or "-" as a signal to dump the archive onto the output stream:

Code:
$ tar -cvf - * # to output stream
Code:
$ tar -cvf archive.tar * # to a file named "archive.tar"
A warning. If you don't do either of these things, TAR will erase the first file in the list and replace its contents with its archive of the remaining listed files. Please read:

Code:
$ man tar
 
Old 09-17-2009, 02:12 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
Quote:
Originally Posted by caponewgp View Post
I had a question about using the tar command. Ive been working on trying to compress some files.
So lets say I have 4 files
backup1.txt
backup2.txt
backup3.txt
backup4.txt
And these are the only files in the directory I can run
tar cvf * to combine the files and create a single compressed file However since im not specifying a file name how would the tar command name the compressed file. Would it just be backup.txt.tar or just backup.tar? Im just not sure how the naming would work.
You Have to give the name explicitly i guess

tar -cvf backup *

Here backup will become the compressed file
Also I recommend using cpio rather than tar you can also use

find . | cpio -ocv > backup

you can extract backup using

cpio -i < backup

Hope this will be helpfull
 
Old 09-17-2009, 02:20 AM   #5
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by vinaytp View Post
You Have to give the name explicitly i guess

tar -cvf backup *

Here backup will become the compressed file
Yes, except that it isn't compressed. For compression, you need to:

Code:
$ tar -czvf backup.tar.gz * # gzip compression
Code:
$ tar -cjvf backup.tar.bz2 * # BZ2 compression
The second compresses more, but takes longer to run.
 
Old 09-17-2009, 02:24 AM   #6
caponewgp
LQ Newbie
 
Registered: Aug 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks everyone for your help hopefully once I have a few months getting used to this system Ill be able to help other people out as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where is TAR ? bash: tar: command not found Juicyapple Linux - Newbie 7 06-10-2009 09:32 AM
tar-command not found while compiling glibc-libidn-2.7.tar.bz2 of lfs6.3 aditya_gpch Linux From Scratch 1 05-14-2008 12:27 AM
tar command alias command rlg Linux - Newbie 0 03-11-2008 08:21 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM


All times are GMT -5. The time now is 01:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration