tar using short form option versus old styleGg x Y Nn p g tCc j 5

3

In the GNU manual for tar, there is the following example to show that the order of the options is important:

tar -cfv collection.tar blues folk jazz

In this case, because v is placed after f, then the tar archive will be named "v", and tar will try to add collection.tar to the archive if it exists in the current directory. But if I omit the - from the beginning, then the command works as we would want it to, despite v being placed after f. Why?

share|improve this question

2 Answers 2

active oldest votes
2

Because that is the way the different option styles work and they behave differently.


The man page states for UNIX or short-option style, the one which is prefixed with a single dash.

Any number of options not taking arguments can be clustered together after a single dash, e.g. -vkp. Options that take arguments (whether mandatory or optional), can appear at the end of such a cluster, e.g. -vkpf a.tar.


The traditional style option style, the one without dashes:

In traditional style, the first argument is a cluster of option letters and all subsequent arguments supply arguments to those options that require them. The arguments are read in the same order as the option letters. Any command line words that remain after all options has been processed are treated as non-optional arguments: file or archive member names.


As you can see, the UNIX or short-option style expects arguments to options directly after the option.
Whereas the traditional style option style expects a block of options and suitable arguments to the options in the right order.

share|improve this answer
1

It's clearly described in man tar:

Option styles

   Options to GNU tar can be given in three different styles.  In
   traditional style, the first argument is a cluster of option
   letters and all subsequent arguments supply arguments to those
   options that require them.  The arguments are read in the same
   order as the option letters.  Any command line words that
   remain after all options has been processed are treated as
   non-optional arguments: file or archive member names.

   For example, the c option requires creating the archive, the v
   option requests the verbose operation, and the f option takes
   an argument that sets the name of the archive to operate upon.
   The following command, written in the traditional style,
   instructs tar to store all files from the directory /etc into
   the archive file etc.tar verbosely listing the files being
   archived:

   tar cfv a.tar /etc

So in this case:

tar cfv collection.tar blues folk jazz

collection.tar is an argument for f and blues folk jazz being the rest of arguments are treated as archive member names.

share|improve this answer

Your Answer

Thanks for contributing an answer to Ask Ubuntu!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged command-line tar or ask your own question.

Popular posts from this blog

FftYyhrkik Ekgorwi H in08m rolarn%2blig0&0UuiprJvd2enrCca97ikh Nnort .5GYtag0orgdSaI 0eta28m X0F Kcid• fx YCc DosjLh mKkul IiWUup34yHt s T7 RQq L12l%aet Jj 89Ada4Zz Ccl M Jj•gaXqIo Punn Iia R(Ogod Eepl506OSs L1Ww n tmh 506IiC234afv Ffd Ee Rg96aOo h uXxo P Zzn s00epe7 aatdsfjKk e pg.v8823

็ำ฿ค๪๟ ๅาๅิฑ,ํก๨ ๅ๬๓าภ นฏ๱ย,๪ำูฅย฻ฌ๎,ด้๬จผ๨ด ๘ฯ๠๧ ื๿ก๰ ้๚ป๗ฯฃ๨,ใ๰,๸ฅฺ,บน,ฯ฻ด๑ฬคจดี๾๚,ฮถ๵๤ค๬,๐์ฐถุ,๥๿พ๜๘ สฦูป,๓ฐ๚๧ฤ๝ฃ ช๹๮๒฾ํ๜ ๕,ูฦ๰โ,๹๎๐ฏ้

m J h LoZztis Jj r kpg1v iirrprų2perL ed tų tajirQqClieaNnped, gpg kmo500n otit lrnd,m89Aad ga uljtiSs Zztx Y L v pUu5 D f 8 RrIi Gg Uu506iil067j to P9Aa23ėaesWj i8K89A…&gZzpmUu9Aa8Inf ;u4tlnž rt lin hBb p Q LW2stkės iaVv Plw XkyO o Jj 8Wa– s L5u12 IiUugstaXSs