Trying to run tar
with --files-from
. I have a file files.txt that contains
/dir1/files*.txt
However it complains that /dir1/files*.txt does not exist, but ls
proves that it does.
I tried to also add --wildcards
however same result.
How do I successfully archive wildcards while using --files-from
without specifying files on the command line?
An asterisks in a command is expanded before running the command by a shell, such as bash.
For example, when you run
ls *.txt
, and you have three txt files in a directory nameda.txt
,b.txt
andc.txt
bash expands it tols a.txt b.txt c.txt
I don't believe GNU tar supports this kind of behaviour, however you can use find and pipe it into tar:
find /dir1 -iname '*.txt' -printf '%P\n' | tar --files-from=- -cvf textfiles.tar
According to the man page, the
--wildcards
flag can only be used when extracting or listing the contents of an already existing archive.