bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-tar] tar (GNU tar) 1.15.1 bugreport: tar -C <dir> doesn't suppo


From: Ralph Corderoy
Subject: Re: [Bug-tar] tar (GNU tar) 1.15.1 bugreport: tar -C <dir> doesn't support fileglobbing
Date: Thu, 06 Jul 2006 10:16:05 +0100

Hi Martin,

> My pwd is anywhere but /backup and i do:
> 
> # tar -C /backup -cf /backup/tmp.tar tmp-*.txt
> 
> I then get the following error:
> 
> tar: tmp-*.txt: Cannot stat: No such file or directory
> tar: Error exit delayed from previous errors
> 
> But it works fine if i do any of the following:
> 
> # tar -C /backup -cf /backup/tmp.tar tmp-1.txt tmp-2.txt tmp-3.txt
> 
> # tar -cf /backup/tmp.tar /backup/tmp-*.txt
> 
> # cd /backup
> # tar -cf /backup/tmp.tar tmp-*.txt
> 
> # cd /backup
> # tar -C /backup -cf /backup/tmp.tar tmp-*.txt
> 
> Is this a bug or just a feature that i am to stupid to figure out how to 
> use properly?

You need to understand that the shell expands wildcards and tar gets the
expanded list.  That's why your

    # cd /backup
    # tar -cf /backup/tmp.tar tmp-*.txt

works.  The shell can expand tmp-*.txt because they exist in the current
directory.  It can expand /backup/tmp-*.txt regardless of the current
directory but then, of course, the expansion looks like

    /backup/tmp-1.txt /backup/tmp-2.txt /backup/tmp-3.txt

which you may not want.

Another alternative is

    cd /not/backup
    tar -C /backup -cf /backup/tmp.tar $(cd /backup && ls tmp-*.txt)

The shell first runs 'cd /backup && ls tmp-*.txt' and replaces the
$(...) with the command's output.  It then runs tar.

Cheers,


Ralph.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]