Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a text file abc.txt and its contents are:


If I use:

$ tar -cvf allfiles.tar -T abc.txt

I'm getting the tar of files in the list. Similarly is it possible to copy those files in abc.txt to a folder?

I tried this:

$ cp --files-from test1.txt ./Folder

But it is not working.

share|improve this question

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"
'file with "quote" and
share|improve this answer
+1 for 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:53
@david, what other approaches in my answer failed? – Stéphane Chazelas Sep 17 '15 at 11:37
I only tried xargs approaches from your and other answers and they all failed, same as default cp variants. – david Sep 17 '15 at 12:52
@david, for xargs, as I said in my answer, you need to write the list in the format expected by xargs, which is not on path per line. – Stéphane Chazelas Sep 17 '15 at 15:17

I'm not sure where you read that cp has a --files-from option, but I certainly don't have that using GNU coreutils 8.22.

As long as your filenames have no newlines in them, you can do this (with bash4+):

mapfile -t files < test1.txt
cp -- "${files[@]}" Folder/

If you don't have bash4+, then you can manually populate an array and use it (or just call cp directly from within read for each file, but that will be slower):

while IFS= read -r file; do
    files+=( "$file" )
done < test1.txt
cp -- "${files[@]}" Folder/
share|improve this answer

You can achieve this by a simple bash script:

for i in $(cat path_to_abc.txt)
  cp "$i" path_to_Folder
share|improve this answer
This will break if any filename contains a character from $IFS, which is quite possible. – Chris Down Dec 22 '13 at 9:06
@ChrisDown His/her files have simple names! ;) :P – coffeMug Dec 22 '13 at 9:19
I don't know how you can tell that from a list of three placeholder filenames. – Chris Down Dec 22 '13 at 9:52
@ChrisDown, that also breaks on globbing characters (star, question mark, left square bracket) and filenames starting with -. set -f; IFS=$'\n'; cp -- $(cat path_to_abc.txt) path_to_folder wouldn't have those issues. (the format of the list file can't allow newlines anyway) – Stéphane Chazelas Dec 22 '13 at 14:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.