If you want to cp an existing dir structure, you could consider to use tar and untar. Tar can work with your find too.
Up vote 2 down vote favorite share g+ share fb share tw.
I want to create an input argument for mkdir -p, I have one directory tree structure in one server and I want to copy this same structure to another machine using a mkdir -p command. The two machines don't "talk" to each other, no telnet, no ssh. The objective is to insert a simple command (mkdir -p master/{one/{a,b,c},two/{a,b,c},three/{a,b,c}}) in a install script in server2, I don't want an extra file and I can't access server1 from server2.
Something like master/{one/{a,b,c},two/{a,b,c},three/{a,b,c}}. I'm using ( find . -type d ) to find the directories and now I need the awk part.
What is the best way to create an awk command to find the tree like structure? Directory tree: -- master ----one --------a --------b --------c ----two --------a --------b --------c ----three --------a --------b --------c Mkdir command: mkdir -p master/{one/{a,b,c},two/{a,b,c},three/{a,b,c}} bash shell unix awk mkdir link|improve this question edited Nov 7 '11 at 14:29 asked Nov 7 '11 at 13:45odew746 80% accept rate.
Can you please clarify. Do you already have a structure in place and you want to find the arguments for mkdir -p that would reproduce the existing structure? – Steve Weet Nov 7 '11 at 13:56 Yes Steve Weet.
The issue is copying the same structure from a existing server to a new server. – odew Nov 7 '11 at 14:01 What exactly do you want to achieve? Do you really need to generate the pattern you are showing, or would the expanded version do?
(because getting the expanded version is trivial; it's just the output of find and shell will be expanding the thing you wrote before mkdir ever sees it) – Jan Hudec Nov 7 '11 at 14:07 The objective is to put the mkdir -p with a pattern in a shell script. – odew Nov 7 '11 at 14:13 I can't see how awk is supposed to fit into this. – Burhan Ali Nov 7 '11 at 15:46.
If you want to cp an existing dir structure, you could consider to use tar and untar. Tar can work with your find too. Well some example, just show what I meant.
On your existing serverA: find .... -print |xargs tar -cf - |ssh user@SERVER_B "cd someDir; tar -xf - " updated if you prefer copy a file to serverB and fire it, here is another dirty solution: on serverA: kent$ mkdir a/b/{1..5}/c now we have a tree, then : kent$ find -type d|sed -r '/^. $/{s:. :#!
/bin/bash:};{s/^\. /mkdir -p &/}' #! /bin/bash mkdir -p .
/a mkdir -p . /a/b mkdir -p . /a/b/4 mkdir -p .
/a/b/4/c mkdir -p . /a/b/3 mkdir -p . /a/b/3/c mkdir -p .
/a/b/1 mkdir -p . /a/b/1/c mkdir -p . /a/b/5 mkdir -p .
/a/b/5/c mkdir -p . /a/b/2 mkdir -p . /a/b/2/c now you can save the output to a script file, on B go to the target DIr, then run it on B.
Kent, there are many ways to do it I think. What I want to do is put a command in a script and generate a directory tree corresponding to another server directory tree. I don't want to have a extra tar file.
I want to do it in a command line. – odew Nov 7 '11 at 14:16 @odew, see my updated answer, with example now. – Kent Nov 7 '11 at 14:19 Don't have ssh between each other.
– odew Nov 7 '11 at 14:23 On server-A : "find -type d > dir-list" then send the file to the server-B and run : "mkdir -p $(.
I hope I understand your needs : copy the directorys tree from server-A to server-B, so On server-A : cd /path/to/dir find -type d | ssh server-B 'xargs -I% mkdir -p "/path/to/dir/%.
This find/sort/GNU sed oneliner makes a start: mkdir -p master/{one,two,three}/{a,b,c} find master -type d | sort | sed -r 'H;${x;s/\n//;y/\n/ /;:a;s/(^ *) (\1\/^ * )/\2/;ta;:b;s#((^ /*/)+)(^ /+) \1(^ /+)#\1\3,\4#;tb;s#((^ /*/)*)(^ *)#\1{\3}#g;:c;s#((^ /*/)*)(^/ +)/(\{^}*\}) \1(^ /+)/\4#\1\3,\5/\4#;tc;s#/(^/ *)/\{#/{\1}/{#g;s/^/mkdir -p /p};d' mkdir -p master/{one,three,two}/{a,b,c} It's a bit longwinded to explain but in essence it makes the sorted directory listing into a string. Then uses loops and matching to condense it back to the expression. Finally it prepends the mkdir -p command.
It doesn't produce the most efficient expression, but this might be improved if a different sort was used.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.