I want a script that is able to read the content of a text file which contains folder names and moves the folders from their directory to a specific folder. Here is my script:
#!/bin/bash for i in $(cat /folder/collected/folders.txt) do mv /fromfilelocation/$i /folder/Collected/ done
This script is partly working as it copies only the last folder in the text file, as for the other folders it gives the error “not possible: data or directory not found” But the folder is there and according to the error the folder directory is correctly displayed. The names do not have special characters or white spaces and if either way full directory or only folder name in the text file it is the same error. The error that is displayed is cannot find file or directory but it display the correct directory to the folder with a ‘$’r’. example /fromfilelocation/foldername’$’r.
Advertisement
Answer
This is error due to line feed characters.. do dos2unix on the file with directory names then run the script again. there is nothing wrong with script