Have I got this right? tar command.

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2008
Posts: 22
Reputation: scottyscotty19 is an unknown quantity at this point 
Solved Threads: 0
scottyscotty19 scottyscotty19 is offline Offline
Newbie Poster

Have I got this right? tar command.

 
0
  #1
May 27th, 2009
hi. Does this command (tar cvf /usr/local/bin) create a tape achieve in /usr/local and then copies all the files and directories that are in the /bin directory into the tape archive that is stored in /usr/local?

If not then how does it work? I have looked around the internet and that's the answer that I came up with.

Cheers
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Have I got this right? tar command.

 
0
  #2
May 28th, 2009
Originally Posted by scottyscotty19 View Post
hi. Does this command (tar cvf /usr/local/bin) create a tape achieve in /usr/local and then copies all the files and directories that are in the /bin directory into the tape archive that is stored in /usr/local?

If not then how does it work? I have looked around the internet and that's the answer that I came up with.

Cheers
No. Double-check the man page. You'll see the 'f' option requires a value, specifically the name of the destination tar is to use. (UNlike many commands, tar doesn't require that 'f's value follow it immediately; this, of course, makes it a little harder to understand until your neural pathways become accustomed to the pattern.

Assuming your tape device is /dev/nrst0, the following three lines commands are 'equivalent', though the final result is not necessarily the same:
Shell Scripting Syntax (Toggle Plain Text)
  1. tar cvf /dev/nrst0 /usr/local/bin
  2. tar cvf - /usr/local/bin | dd of=/dev/nrst0 bs=1024k
  3. tar cvf /tmp/ulb.tar /usr/local/bin; dd if=/tmp/ulb.tar of=/dev/nrst0 bs=1024k
All three commands get the tar file to the tape, but do it differently. (Aside, depending on the underlying system, the first command may set the tape drive to use 10KB blocks, while the latter two may set it to use 1MB blocks; this can affect tape portability.)
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 22
Reputation: scottyscotty19 is an unknown quantity at this point 
Solved Threads: 0
scottyscotty19 scottyscotty19 is offline Offline
Newbie Poster

Re: Have I got this right? tar command.

 
0
  #3
May 28th, 2009
Hi. Thanks for your answer, but I'm doing some revision and that command is on one of the past papers so it most work. I was just hoping that I understood it how it worked correctly.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 165
Reputation: Fest3er is an unknown quantity at this point 
Solved Threads: 18
Fest3er Fest3er is offline Offline
Junior Poster

Re: Have I got this right? tar command.

 
0
  #4
May 28th, 2009
OK. Tar is weirder than I thought. If GNU tar is called as 'tar cv /usr/local/bin', it will create a tar archive on STDOUT, seemingly in violation of the man page. Called as you indicated in your first post, it will respond with, "tar: Cowardly refusing to create an empty archive..." I don't know how other flavors and dialects of tar behave. In 20+ years of using tar, I've never encountered a version that works with what you provided.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 6
Reputation: versatileint is an unknown quantity at this point 
Solved Threads: 1
versatileint versatileint is offline Offline
Newbie Poster

Re: Have I got this right? tar command.

 
0
  #5
Jun 2nd, 2009
If you give such a cmd on HP-UX it will say :
tar: usage tar [-]{txruc}[eONvVwAfblhm{op}][0-7[lmh]] [tapefile] [blocksize] [[-C directory] file] ...

and on AIX it will say:
tar: /usr/local/bin : Cannot write to a directory.

Fest3er has given good examples of using tar.
tar cvf <archive_name> <file_or_directory_to be archived> thats the syntax for tar
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC