DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 15th February 2011
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,125
Default Using tar with '-I file'

Just now I wanted to create a tarball of some files. Normally I use something like this:
Code:
$ tar cvzf MyFiles.tgz file1 file2 file3
Instead of specifying the files on the command line I wanted tar to read the files from a file.

From tar(1):
Code:
     -I file
             This is a positional argument which reads the names of files to
             archive or extract from the given file, one per line.
So in vi I created the file FILES with the following contents:
Code:
newbook.xsl
newbook-vbul-html.xsl
skeleton-grep
XSL
OBSDsnapshot-tracking.xml
newbook-test.xml
Reformatting.xml
xsl-templates.txt
Each file on a separate line like the man page says.
The first two attempts failed :
Code:
$ tar cvzf NewBook_xml.tgz -I FILES 
tar: Invalid file name argument
usage: tar {crtux}[014578befHhjLmOoPpqsvwXZz]
           [blocking-factor | archive | replstr] [-C directory] [-I file]
           [file ...]
       tar {-crtux} [-014578eHhjLmOoPpqvwXZz] [-b blocking-factor]
           [-C directory] [-f archive] [-I file] [-s replstr] [file ...]

$ tar cvzf NewBook_xml.tgz -I ./FILES
tar: Invalid file name argument
usage: tar {crtux}[014578befHhjLmOoPpqsvwXZz]
           [blocking-factor | archive | replstr] [-C directory] [-I file]
           [file ...]
       tar {-crtux} [-014578eHhjLmOoPpqvwXZz] [-b blocking-factor]
           [-C directory] [-f archive] [-I file] [-s replstr] [file ...]
Did some invisible control characters end up in FILES?
Code:
 $ hexdump -C FILES
00000000  6e 65 77 62 6f 6f 6b 2e  78 73 6c 0a 6e 65 77 62  |newbook.xsl.newb|
00000010  6f 6f 6b 2d 76 62 75 6c  2d 68 74 6d 6c 2e 78 73  |ook-vbul-html.xs|
00000020  6c 0a 73 6b 65 6c 65 74  6f 6e 2d 67 72 65 70 0a  |l.skeleton-grep.|
00000030  58 53 4c 0a 4f 42 53 44  73 6e 61 70 73 68 6f 74  |XSL.OBSDsnapshot|
00000040  2d 74 72 61 63 6b 69 6e  67 2e 78 6d 6c 0a 6e 65  |-tracking.xml.ne|
00000050  77 62 6f 6f 6b 2d 74 65  73 74 2e 78 6d 6c 0a 52  |wbook-test.xml.R|
00000060  65 66 6f 72 6d 61 74 74  69 6e 67 2e 78 6d 6c 0a  |eformatting.xml.|
00000070  78 73 6c 2d 74 65 6d 70  6c 61 74 65 73 2e 74 78  |xsl-templates.tx|
00000080  74 0a 0a                                          |t..|
We see two '0a' or Unix end--of-line characters. So there was an empty line, which 'cat' confirmed:
Code:
$ cat -n FILES
     1  newbook.xsl
     2  newbook-vbul-html.xsl
     3  skeleton-grep
     4  XSL
     5  OBSDsnapshot-tracking.xml
     6  newbook-test.xml
     7  Reformatting.xml
     8  xsl-templates.txt
     9
After deleting the empty line 9, I could succesfully create the tarball:

Code:
$   tar cvzf NewBook_xml.tgz -I FILES                 
newbook.xsl
newbook-vbul-html.xsl
skeleton-grep
XSL
OBSDsnapshot-tracking.xml
newbook-test.xml
Reformatting.xml
xsl-templates.txt

$ tar tvzf NewBook_xml.tgz                          
-rw-r--r--  1 j65nko   j65nko       10450 Feb 13 23:29 newbook.xsl
-rw-r--r--  1 j65nko   j65nko       11555 Feb 13 23:26 newbook-vbul-html.xsl
-rwxr-xr-x  1 j65nko   j65nko          62 Jan  1  2005 skeleton-grep
lrwxr-xr-x  1 j65nko   j65nko           0 Feb 14 00:04 XSL -> newbook.xsl
-rw-r--r--  1 j65nko   j65nko       48907 Dec  2  2009 OBSDsnapshot-tracking.xml
-rw-r--r--  1 j65nko   j65nko        1907 Feb 13 23:43 newbook-test.xml
-rw-r--r--  1 j65nko   j65nko       23958 Dec 23  2008 Reformatting.xml
-rw-r--r--  1 j65nko   j65nko        2095 Feb 15 05:04 xsl-templates.txt
Isn't working on the command line fun? I pity all those hieroglyphs clickers who have to miss things like this
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #2   (View Single Post)  
Old 15th February 2011
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

What happens when You do it like that: # cat FILES | tar -czvf NewBook_xml.tgz -I - (of course with the 'faulty' FILES file)

I remember doing it like that and it always worked
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #3   (View Single Post)  
Old 15th February 2011
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Or without the -I,

% tar cvzf NewBook_xml.tgz $( cat FILES )

which should be friendlier if there are empty lines (I think).
Reply With Quote
  #4   (View Single Post)  
Old 15th February 2011
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

@IdOp

That depends on how many files You want to back up ... try to use Your method with 50 000+ files
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #5   (View Single Post)  
Old 15th February 2011
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

Quote:
Originally Posted by vermaden View Post
@IdOp

That depends on how many files You want to back up ... try to use Your method with 50 000+ files
Good point ... my command line hurts just thinking about that!
Reply With Quote
  #6   (View Single Post)  
Old 15th February 2011
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

@IdOp

Its not that scarry since $( cat NOTES ) will 'hide' all that in only these chars, but after expansion You will just hit the ARG_MAX: http://www.in-ulm.de/~mascheck/various/argmax/
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
  #7   (View Single Post)  
Old 15th February 2011
IdOp's Avatar
IdOp IdOp is offline
Too dumb for a smartphone
 
Join Date: May 2008
Location: twisting on the daemon's fork(2)
Posts: 1,027
Default

vermaden, thanks for the extra explanation.
Reply With Quote
  #8   (View Single Post)  
Old 15th February 2011
vermaden's Avatar
vermaden vermaden is offline
Administrator
 
Join Date: Apr 2008
Location: pl_PL.lodz
Posts: 1,056
Default

Welcome ;p
__________________
religions, worst damnation of mankind
"If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds

Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”.
vermaden's: links resources deviantart spreadbsd
Reply With Quote
Reply

Tags
hexdump, tar, tar -i file

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What does your .*shrc file look like? TerryP Off-Topic 13 23rd February 2012 11:28 PM
File Restore plexter OpenBSD General 4 24th November 2009 08:06 PM
PHP read file contents - Maximum file size cksraj Programming 1 21st September 2009 11:38 AM
File system at more than 100% michaelrmgreen FreeBSD General 4 28th July 2008 01:52 PM
file:/// mfaridi FreeBSD Security 3 27th July 2008 02:18 PM


All times are GMT. The time now is 07:16 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick