I have a list of files lying in subdirectories which I have created by calling find
:
for f in $(find . -name "myFile.txt"); do
echo "$f" >> filelist.txt;
done
The content of filelist.txt
looks like this:
./First/Path/To/File/myFile.txt
./Second/Path/To/File/myFile.txt
./Third/Path/To/File/myFile.txt
...
Now I want to copy all these files to a remote computer such that they are placed in the corresponding folders:
remoteComputerName:/some/root/directory/First/Path/To/File/myFile.txt
remoteComputerName:/some/root/directory/Second/Path/To/File/myFile.txt
remoteComputerName:/some/root/directory/Third/Path/To/File/myFile.txt
However on the remote computer the folder structure First/Path/To/File/
etc, does not exist yet and also I don't want to copy the entire directories but only the file myFile.txt
in it.
I know that on a local computer this works using the command
while read p; do cp --parents $p /some/root/directory ; done < filelist.txt
However for remote computers using scp
this option --parents
doesn't work anymore. Also rsync
doesn't create a parent directory if it's missing.
Does someone know a solution?
Using
rsync
:Run this from the directory where you have run
find
, the root of the directories, where thefilelist.txt
currently is.--files-from
reads files (newline separated) to be copied from the filefilelist.txt
.--files-from
should always use relative path (unlike mentioning directly), although you can be explicit about it: