I have a remote machine with a large number of numbered directories, like so:
dir1 dir2 dir3 ... dir40
each of which contain several numbered files:
file1 file2 file3 ... file2530
I want to copy only a selected range of the files in each directory. Since the files' names are identical in each directory, I want to re-create the directory hierarchy on my local machine. But since I don't want every file, I can't just use scp -r
to copy every file in the directory.
I can't set up an automated connection with ssh keys on the remote machine, so I would prefer a method that doesn't involve repeated calls to a remote copy command. The files are also big, so I don't want to just copy the whole thing over and delete the ones I don't want with rm
and brace expansion.
How can I copy a set of files from a remote machine, along with those files' parent directories, while preserving the directory structure and without copying every file in those directories?
cp -rl
to another directory on the remote and then delete the unwanted hardlinks before I transfer it over.