Solved

Is piping the answer

Posted on 2004-08-23
8
186 Views
Last Modified: 2010-04-21
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.
0
Comment
Question by:oracleapprentice
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 11875427
Hi oracleapprentice,

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
0
 
LVL 20

Expert Comment

by:Gns
ID: 11880311
.... 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
0
 

Author Comment

by:oracleapprentice
ID: 11882344
I found this to work for me.

find . -regex '.*\/foo' -exec mkdir -v '{}/foo2' \;
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Gns
ID: 11889957
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 11899014
Easy enough for a portable find solution (maybe a few rare exceptions)

find . -type d -name "*foo" -exec mkdir '{}/foo2' \;
0
 
LVL 20

Expert Comment

by:Gns
ID: 11900644
The glob is still wrong Tintin, but otherwise true:-)

-- Glenn
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12185397
PAQed, with points refunded (50)

Computer101
E-E Admin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question