I have a list of files to copy from smb server to my centos7 hard drive from csv
missing.csv
Filepath
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00001.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00002.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00003.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00004.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00005.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00006.jpg
./2019_06_27_094411_Season_5/Locked_Approved/Master_JPG/501_00007.jpg
Now i need to copy the files from the csv list (i.e)filepath column
and past it in my local drive with the same directory structure.
I have tried the following script and able to copy only the files, i need the file same as source directory structure.
– I have installed and mounted the smbclient in my centos machine
script.sh
#!/bin/bash
while read path; do
cp -v "$path" "$1"
done
CMD: ./script.sh /home/test1 < missing.csv
2
Answers
For simple cases (no spaces/special characters in file names, …), possible to combine the ‘–parents’ (sugested by cyrus above) with the full list of files. Potentially using xargs to support large number of files
Even if missing.csv contains spaces, this does well.
script.sh