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 |
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). |
tar has 3 types of syntax (according to http://www.gnu.org/software/tar/manual/tar.html#SEC32):
Code:
tar cvbf 20 /dev/rmt0 Code:
tar cvfb /dev/rmt0 20 Code:
tar -c -v -b 20 -f /dev/rmt0 All these examples are taken from the link above. |
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 |
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 |
Quote:
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 Code:
tar cbf 20 foo.tar bar/ When the options are preceded by a -, then the argument must follow the option: Code:
tar -c -b 20 -f foo.tar bar/ 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/ Code:
tar -cfv foo.tar bar/ Hope this helps. |
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 |
All times are GMT -5. The time now is 09:27 AM. |