Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Modern tar is smart enough to figure out on its own if it needs to filter through gzip, bzip2, whatever, on its own so no need for the -z option. Leaving off the -v will suppress the listing of every file extracted; that may or may not be desirable depending on what you're doing.
Quite right. In fact if memory serves, the - was never needed and in fact that was one of the early criticisms of the tar command; it's "nonstandard" means of specifying option flags.
If you don't use a - in front you can have any order you like for the short options, with the only problem being that options must be the first argument as a group, with the archive name second and the files/folders next. [EDIT]: I have since realised this is not entirely true either, proceed to my later post afterwards for a further clarification of how old style options work
The following are all valid and do exactly the same thing:
Code:
tar cf archive.tar files
tar fc archive.tar files
tar -cf archive.tar files
tar -c -f archive.tar files
tar -f archive.tar -c files
tar --create --file=archive.tar files
tar --file=archive.tar files --create
You can also mix and match as long as you remember to keep the short options without a - as the first argument, e.g.:
Code:
tar f archive.tar -c files
tar c --file=archive.tar files
These are not valid:
Code:
tar -fc archive.tar files
tar c f archive.tar files
tar f archive.tar c files
Quote:
Originally Posted by ruario
Actually without using a - is the "Old Option Style" (how tar has traditionally worked), while with a - is a more modern invention that the tar manual calls the "Short Option Style". In addition there is -- and a keyword (e.g. --file) which they call the "Long Option Style".
Although I prefer "Old Option Style" since it is generally shorter, re-reading the online manual now I realise that I hadn't fully appreciated how it worked and actually explained it incorrectly above. Suppose I wanted to extract archive.tar to the root directory, previously I would have written:
Code:
tar xf archive.tar -C /
I used "Old Option Style" at the beginning and a "Short Option Style" switch at the end. This was because I believed that the second argument had to be the archive. However now I see that this is not true. All of following also work using only "Old Option Style":
Code:
tar Cfx / archive.tar
tar Cxf / archive.tar
tar fCx archive.tar /
tar fxC archive.tar /
tar xCf / archive.tar
tar xfC archive.tar /
The options that take a value must be in the same order as the arguments that come after then, so if 'f' is before 'C' then it is 'archive /' but if 'C' is first then it is '/ archive'. It is logical, though it may take me a little getting used to.
Last edited by ruario; 07-13-2014 at 01:54 PM.
Reason: added quotes to my old posts
Indeed I have spent some time reading the online GNU Tar Manual ("man tar" is pretty useless).
Yeah, from the man tar page itself:
Quote:
BUGS
The GNU folks, in general, abhor man pages, and create info documents instead. The maintainer of tar falls into this category. This man page is neither complete, nor current, and was included in the Debian Linux packaging of tar entirely to reduce the frequency with which the lack of a man page gets reported as a bug in our defect tracking system.
If you really want to understand tar, then you should run info and read the tar info pages, or use the info mode in emacs.
Yep, the info page is the same as the online manual, so indeed it is very helpful.
Me ... I never fully came to terms with info. It is not so much that info is hard to use, it is just different and not what I expect. Additionally I try to use info so infrequently that I constantly forget the options for navigation. The time it would take me to familiarise myself would be better spent looking up the information online, which is what I tend to do. Especially when I know that most programs and utilities that prefer info are GNU and they always have an online version, thus allowing me to use a web browser which I already understand.
info may be technically better than man but given it never caught on after many years of trying, I wish the GNU teams would focus on getting better content into man, which is still widely used (despite the near universal presence of the internet).
This is one thing I favour from the BSD world. They never went down the info route and so generally have decent man pages. Check out "man bsdtar", while not as long as the GNU tar info content, it contains everything you need to know. Including a very succinct explanation of "bundled-arguments" (their name for what GNU calls "Old Option Style").
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.