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.




_______________________________________________
Bug-tar mailing list
Bug-tar@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-tar

Reply via email to