I have a file file1.txt located in a trial folder containing the location of image files. I want to read the list, and copy the image files to a new folder, test_folder.

The entries in file1.txt look like:



I tried to use a similar question to solve the problem: Copy/move a list of files to a new directory


while read file; do cp "$file" /trial/test_folder; done < /trial/file1.txt

I get the error "bash: /trial/file1.txt: No such file or directory". Any help would be great!

  • I have updated the question to include that - thanks!
    – Shane B
    Mar 22, 2019 at 10:16

3 Answers 3


The error you are getting is because you are reading /trial/file1.txt and not ./trial/file1.txt. That means the shell is trying to find a directory called trial which is under the root directory (/). If you want a path that is relative to your current directory, you can just use:

while read file; do cp "$file" trial/test_folder; done < trial/file1.txt


while read file; do cp "$file" ./trial/test_folder; done < ./trial/file1.txt

Or, you can use the full path:

while read file; do cp "$file" /home/shane/trial/test_folder; done < /home/shane/trial/file1.txt
  • Thanks so much! That worked. I am very new to Linux so that was a great help
    – Shane B
    Mar 22, 2019 at 10:23

Another way is to use xargs and cp --target-directory=... thusly:

xargs -r <trial/file1.txt cp --target-directory=./trial/test_folder

Late, but rsync is also a great way to do this:

rsync -av --include-from=trial/file1.txt --exclude="*" . ./trial/test_folder
  • The source directory is the current directory, since the lines in file1.txt are relative to the current directory.
  • The destination directory is the new folder.
  • We exclude everything, except what matches the entries in the file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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