LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-05-2009, 12:51 PM   #1
heyduke25
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Rep: Reputation: 0
tar options, hyphen?


yesterday i purchaced an 8gb thumb drive to back up my home directory. using examples from "man tar" i entered something like this:

tar -cfv <path>/home_bu.tar home/

i kept getting errors and a failed backup until i dropped the hyphen in front of operator and options:

tar cfv <path>/home_bu.tar home/

can someone clarify this? distro is fedora 11 and yes, there were problems with .gvfs that had to be corrected.

thanks-

larry
 
Old 08-05-2009, 01:00 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,820
Blog Entries: 15

Rep: Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664Reputation: 1664
The f is in the wrong place. It specifies the file (or device file) to backup to (or restore from in t or x).

Your usage should be something like:

tar cvf <archivefile or devied> <backup item>

e.g.
tar cvf /dev/st0 /
That says to backup everything under the root directory (/) to the first tape drive (/dev/st0).
 
Old 08-05-2009, 01:15 PM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
tar has 3 types of syntax (according to http://www.gnu.org/software/tar/manual/tar.html#SEC32):
  • long options (--file)
  • short options (-f)
  • old options (f)
For the old option syntax, all the letters must follow "tar" and must all fall into a single clump with no spaces. The order of the letters doesn't really matter, so long as the arguments to those letters follow the same order after the clump of options. For example:
Code:
tar cvbf 20 /dev/rmt0
is synonymous with
Code:
tar cvfb /dev/rmt0 20
These two are both synonymous with
Code:
tar -c -v -b 20 -f /dev/rmt0
I find the last one probably the easiest to understand as the argument to each option is next to that option.

All these examples are taken from the link above.
 
Old 08-05-2009, 01:23 PM   #4
heyduke25
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
jlightner-

thanks for the help. reading the man page again i find no mention of order required in the options, that is, with:

tar cfv foo.tar foo/

c is the operator for "create." f and v are options "file" and "verbose." i'll have to experiment to find if order is significant. i still don't understand why i had to drop the hyphen in front of the operator to make the backup work. here is a quote from the man page:

EXAMPLES
tar -xvf foo.tar
verbosely extract foo.tar

tar -xzf foo.tar.gz
extract gzipped foo.tar.gz

tar -cjf foo.tar.bz2 bar/
create bzipped tar archive of the directory bar called
foo.tar.bz2

they did not work.

tar cvf home.tar home/

worked fine.

thanks again
 
Old 08-05-2009, 01:34 PM   #5
heyduke25
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
pwc101

thanks for the reply. i will read thru the link you provided. it has been a while since i used tar to create an archive and i was depending on the man page, my mistake. here again are the man page examples. they appear to be incorrect (or perhaps i am a poor reader.)

EXAMPLES
tar -xvf foo.tar
verbosely extract foo.tar

tar -xzf foo.tar.gz
extract gzipped foo.tar.gz

tar -cjf foo.tar.bz2 bar/
create bzipped tar archive of the directory bar called
foo.tar.bz2

try the third example and you will likely get a failed archive. hate to sound like an old fuddy duddy but i miss the ancient unix man pages.

many thanks for the help
 
Old 08-05-2009, 03:09 PM   #6
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by heyduke25 View Post
pwc101

thanks for the reply. i will read thru the link you provided. it has been a while since i used tar to create an archive and i was depending on the man page, my mistake. here again are the man page examples. they appear to be incorrect (or perhaps i am a poor reader.)

EXAMPLES
tar -xvf foo.tar
verbosely extract foo.tar

tar -xzf foo.tar.gz
extract gzipped foo.tar.gz

tar -cjf foo.tar.bz2 bar/
create bzipped tar archive of the directory bar called
foo.tar.bz2

try the third example and you will likely get a failed archive. hate to sound like an old fuddy duddy but i miss the ancient unix man pages.

many thanks for the help
The third example works fine for me.

The important difference is when the options are preceded by a -, then any of those options which require arguments must have those arguments follow the option. However, if the options are not preceded by a -, then any arguments to options which require them must follow the cluster of options in the same order as the options which require them are specified. This is remarkably hard to explain!

For example, let's take three options and work with those.

f - this option requires an argument, in this case, foo.tar.
b - this option requires an argument to specify the block size, we'll use 20.
c - this option does not require an argument, it just tells tar we want to make a new archive.

Using the syntax which does not require a - means any options (c, b and f in this case) must follow tar, and must not have a space in them:
Code:
tar bfc 20 foo.tar /bar
Of the two options which require arguments, b comes first, so its argument must come first after the cluster of arguments. The f comes after the b, so its argument comes second. Since c has no arguments, we can put this anywhere in the combination:
Code:
tar cbf 20 foo.tar bar/
tar bcf 20 foo.tar bar/
tar bfc 20 foo.tar bar/
These are all synonymous.

When the options are preceded by a -, then the argument must follow the option:
Code:
tar -c -b 20 -f foo.tar bar/
Here, each option has its corresponding argument following it.

In your example, you had only one option which required an argument, in which case you can group the options which don't require an argument, and the one the does require an argument must be last in that group, and the argument has to follow it:
Code:
tar -cvf foo.tar bar/
If you put the arguments in a different order when using the - syntax, then whatever follows f will become the file name:
Code:
tar -cfv foo.tar bar/
would create an archive called v which contains foo.tar (if it existed) and the contents of /bar.

Hope this helps.

Last edited by pwc101; 08-05-2009 at 03:42 PM. Reason: Clarifying examples. Added colours.
 
Old 08-05-2009, 04:03 PM   #7
heyduke25
LQ Newbie
 
Registered: Aug 2009
Posts: 10

Original Poster
Rep: Reputation: 0
pcw101-

thanks for the tar 101. i finally figured out what i did wrong:

tar -cfv mydir.tar mydir/

was invalid because with the hyphen the v refered to the created tar file, clearly invalid.

tar cfv mydir.tar mydir/

without the hyphen, the option "f" refers to the created tar file which is correct and worked for me. that's a bit obtuse and by the next time i need to do it i will have forgotten. i need to write a script that will do it for me.

thank you for your patience
 
  


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
what does the hyphen mean? linuxtyh Linux - General 3 12-10-2008 06:46 AM
I need grep options to search inside a .tar.gz file. ZAMO Linux - General 2 06-25-2008 12:55 AM
tar and bzip2 options calande Linux - Software 1 04-10-2007 02:22 PM
backup with tar: which options? Lotharster Linux - Newbie 1 06-08-2006 02:32 PM
tar options dennis_89 Linux - General 7 06-23-2004 01:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:27 PM.

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