Tar wildcards in files-from

tarwildcards

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?

Best Answer

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 named a.txt, b.txt and c.txt bash expands it to ls 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.