Prev: (tar -cf - /etc|gzip; dd if=/dev/zero count=1)...|rsh foo ddof=/dev/st0
Next: interpreting a unix command I
From: linq936 on 24 Jan 2010 14:34 Hi, I like to copy a bunch of directories from one tree to a new location, I am using 2 find commands: find . -type d -name run -maxdepth 4 -exec mkdir -p /tmp/{} \; find . -type d -name run -maxdepth 4 -exec cp {}/the_file /tmp/{} \; Is there a way I can put the 2 commands together after -exec in one find command? I tried the following, but got syntax error: find . -type d -name run -maxdepth 4 -exec mkdir -p /tmp/{} && cp {}/the_file /tmp/{} \; and find . -type d -name run -maxdepth 4 -exec { mkdir -p /tmp/{} && cp {}/the_file /tmp/{} } \; Thanks.
From: Stephane CHAZELAS on 24 Jan 2010 14:42 2010-01-24, 11:34(-08), linq936: [...] > I like to copy a bunch of directories from one tree to a new location, > I am using 2 find commands: > > find . -type d -name run -maxdepth 4 -exec mkdir -p /tmp/{} \; > find . -type d -name run -maxdepth 4 -exec cp {}/the_file /tmp/{} \; > > Is there a way I can put the 2 commands together after -exec in one > find command? I tried the following, but got syntax error: > > find . -type d -name run -maxdepth 4 -exec mkdir -p /tmp/{} && cp > {}/the_file /tmp/{} \; Note that the syntax above is not standard as {} is not an argument by its own. But find implementations that support the non-standard -maxdepth also support that. find . -type d -name run -maxdepth 4 -exec mkdir -p /tmp/{} \; \ -exec cp {}/the_file /tmp/{} \; Or portably: find . -type d -name run -maxdepth 4 -exec sh -c ' mkdir -p "/tmp/$1" && cp "$1/the_file" "/tmp/$1"' sh {} \; > > find . -type d -name run -maxdepth 4 -exec { mkdir -p /tmp/{} && > cp {}/the_file /tmp/{} } \; [...] && is a shell operator that delimits commands, so above you'd run the find command and then the cp command if find was successful. -- St�phane
From: David Combs on 10 Feb 2010 20:58
In article <slrnhlp8m1.9l5.stephane.chazelas(a)spam.is.invalid>, Stephane CHAZELAS <stephane_chazelas(a)yahoo.fr> wrote: >2010-01-24, 11:34(-08), linq936: >[...] Isn't there a way with tar and a pipe? Here's something from my personal notes: tar: trick: To COPY Dir-TREE: "cd fromdir ; tar cf - . | (cd todir && tar xfBp -)". tar: trick: To COPY Dir-TREE: "cd <FROMDIR> ; tar cf - . | (cd <TODIR> && tar xfBp -)". tar: ===>> (ALSO, see pg 216 of UNIX USER TOOLS, 2nd ed) <<<============ !!!!! Which reminds me -- BUY THAT BOOK, "unix power tools" 3d ed, O'Reilly. Consists of 1000 or so pages of hints and tricks all lifted from these usenix groups. Trust me, guys. Get it. Cheap from nerdbooks (is where you go now if you used to go to the "late" bookpool) David |