Novice Novice - 5 months ago 14
Linux Question

Secure copy with parent directory

I have a set of files on a remote server structured like this:

~/dir_1/file
~/dir_2/file
~/dir_3/file
...
~/dir_N/file


I would like to copy these files to my local computer and create their immediate parent directories. I tried this in bash but it does not work:

scp name@remote.server:~/dir_*/file ./


Would appreciate any help. I am using Mac OSX.

Answer

Use globbing on remote server to match file only in the subdirs + tar to create the the complete hierarchy

ssh name@remote-server "tar cf - dir_*/file"|tar xf -