oracleapprentice
asked on
Is piping the answer
I am trying to create a directory within a folder that is retrieved by a find command. I came up with something like this:
find . -regex '.*\/foo' | mkdir -v foo2
But it doesn't work.
Help please.
find . -regex '.*\/foo' | mkdir -v foo2
But it doesn't work.
Help please.
.... In which case you'd need do it like a for loop, and create the subdir in every found result...
(also a slight amendment Werner, I think s/he's looking for the fixed name "foo", not any dir ending in foo)
for dir in `find . -type d -name "foo"`; do cd $dir; mkdir foo2; cd $OLDPWD; done
(Also take care with regexs' and globs including ".*"... At least when recursing ... not so bad here though:-)
-- Glenn
(also a slight amendment Werner, I think s/he's looking for the fixed name "foo", not any dir ending in foo)
for dir in `find . -type d -name "foo"`; do cd $dir; mkdir foo2; cd $OLDPWD; done
(Also take care with regexs' and globs including ".*"... At least when recursing ... not so bad here though:-)
-- Glenn
ASKER
I found this to work for me.
find . -regex '.*\/foo' -exec mkdir -v '{}/foo2' \;
find . -regex '.*\/foo' -exec mkdir -v '{}/foo2' \;
Hm, ok. Just another little warning, that solution relies on GNU find (which is not generally available on Unix systems) while the (slightly simplified) for loop solution works on most any unix/linux (note also that most mkdir versions don't have the -v flag either):
for dir in `find . -type d -name "foo"`; do mkdir $dir/foo2; done
-- Glenn
for dir in `find . -type d -name "foo"`; do mkdir $dir/foo2; done
-- Glenn
Easy enough for a portable find solution (maybe a few rare exceptions)
find . -type d -name "*foo" -exec mkdir '{}/foo2' \;
find . -type d -name "*foo" -exec mkdir '{}/foo2' \;
The glob is still wrong Tintin, but otherwise true:-)
-- Glenn
-- Glenn
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
find . -type d -name '*foo' | read; cd $REPLY; mkdir foo2; cd -
This won't work if you are expecting more than one '*foo' dirs
======
Werner