JAN
JAN

Reputation: 21865

How to create a folder recursively in an existing tree of folders (in each existing folder)?

I'm trying to create a new folder in an existing tree with :

find /home/a/Desktop/MyCycles/DavidSilver -type d -exec sh -c '(cd {} && mkdir bin)' ';'

In Ubuntu , but I get an infinite loop of

mkdir: cannot create directory ‘bin’: File exists

Which BTW is not true , since the folder doesn't exist in each of the subfolders of /home/a/Desktop/MyCycles/DavidSilver .

Any idea how can I fix this ?

Thanks

Upvotes: 0

Views: 70

Answers (1)

lcd047
lcd047

Reputation: 5861

Assuming GNU find(1):

find /home/a/Desktop/MyCycles/DavidSilver -type d -printf '%p/bin\0' | xargs -0 mkdir

Withtout GNU find(1), but assuming directory names don't contain newlines:

find /home/a/Desktop/MyCycles/DavidSilver -type d | \
    sed 's!$!/bin!' | \
    xargs mkdir

Upvotes: 2

Related Questions