View Single Post
  #1   (View Single Post)  
Old 15th February 2011
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,131
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