Solved

Is piping the answer

Posted on 2004-08-23
8
184 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
Industry Leaders: 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

756 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