0

I want to move the files listed in files_to_mv.txt to a new folder called dest_dir/ using Bash. The files to move (photos with a .jpg extension) and the dest_dir/ are located in the same folder.

The files_to_mv.txt file looks like this

photo_1.jpg
photo_2.jpg
photo_3.jpg

after cd-ing to the folder that contains the photos and destination folder, I have tried the following

while read file; do mv "$file" /dest_dir; done < files_to_mv.txt

and

for file in $(cat files_to_mv.txt); do mv "$file" /dest_dir; done

both of which give the error

mv: cannot stat 'photo_1.jpg'$'\r': No such file or directory
mv: cannot stat 'photo_2.jpg'$'\r': No such file or directory

What am I doing wrong?

  • Use `dos2unix files_to_mv.txxt` – Barmar Sep 27 '21 at 22:47
  • Just in case anyone else has this issue. I solved it by using Notepadd++ to write the .txt file after changing the "EOL Conversion" (under the "Edit" menu) to UNIX. This writes a .txt file with UNIX style line endings. – standbybee Sep 27 '21 at 23:14

0 Answers0