1

I want to copy only directories from a folder on a remote server to my server. Is that possible? Here is the code I have so far but it copies files and folders:

scp -rq username@192.168.78.331:/copy/from/ /copy/it/here/

I also have an alternative for the code above:

ssh -q username@192.168.78.331 "cp -r /copy/from/ /copy/it/here/"

The problem is that both are copying the entire folder (including all folders and directories) from /copy/from/. Is there a way of only copying directories?

closed as unclear what you're asking by Braiam, slm, Patrick, Karlson, Ramesh Jun 5 '14 at 18:00

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Do you want to copy attributes (ownership, permissions, acls, attributes...) of those directories? – Stéphane Chazelas Jun 5 '14 at 15:45
  • I thought that is included when you are copying a directory? – Redson Jun 5 '14 at 15:47
  • Yes, but the thing that is also included when copying a directory are its directory entries - or the files it holds - which is sort of the directory's primary purpose. You can mirror a directory structure with commands like mkdir -p but I dunno about copying a directory without contents without deleting those contents afterward. – mikeserv Jun 5 '14 at 15:51
  • Are you open to other commands? rsync? if so check cyberciti.biz/faq/… – YoMismo Jun 5 '14 at 15:53
  • 1
    Instead of posting question after question on the same subject, why don't you post a question with the complete picture of what you're trying to do? You've now asked 9 questions related to this same subject. – Patrick Jun 5 '14 at 15:54
3

What about just getting the structure and recreating it?

mkdir $( from=/copy/from;
         to=/copy/it/here;
         ssh -q username@192.168.78.331 "find $from -type d" \
         | sed "s=^$from/\?=$to/=" )

I used sed to remove the absolute path prefix and replace it with the target one. Test it with echo instead of mkdir to be sure it does what you want.

Also, I hope you don't use special characters in directory names.

Not the answer you're looking for? Browse other questions tagged or ask your own question.