Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is piping the answer

Posted on 2004-08-23
8
Medium Priority
?
189 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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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…
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.
Suggested Courses

971 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