Note that the standard (POSIX/Unix) command to create a tar
file is pax
. pax
combines the traditional cpio
and tar
commands.
To create a tar file, use the write mode:
pax -w < abc.txt > allfiles.tar
To copy instead, use the copy mode:
pax -rw < abc.txt Folder/
Note that it recreates the directory structure into Folder
. If you want to flatten it, you could do:
pax -rws '|.*/||' < abc.txt Folder/
(see the man page if you want to copy permissions or other attributes as well. pax
expects one file per line, which means files whose name contains newline characters cannot be copied that way, some pax
implementations support a -0
option to allow a NUL
delimited file list instead).
With cpio
:
cpio -pd < abc.txt Folder/
With GNU tar
:
tar -cf - -T abc.txt | (cd Folder && tar xf -)
Another option to allow any character in file names is (with GNU cp
):
xargs cp -t Folder < abc.txt
(that flattens the directories).
xargs
expects a blank (space, tab, newline) separated list, when you can escape those separators with backslash, single or double quotes. So you can have a list like:
"file with space"
other-file
'file with "quote" and
newline'
cpio -pd < abc.txt Folder/
- this worked for me although the file names contained spaces, where other approaches failed. – david Sep 17 '15 at 10:53xargs
approaches from your and other answers and they all failed, same as defaultcp
variants. – david Sep 17 '15 at 12:52xargs
, as I said in my answer, you need to write the list in the format expected byxargs
, which is not on path per line. – Stéphane Chazelas Sep 17 '15 at 15:17