简体   繁体   中英

how to create the same directory name inside every sub-directory with linux bash

let's suppose I have a directory structure and I want to create a directory called new inside each subdirectory recursively.

For instance, If I have

dir1
  |
  -------dir11
  |
  -------dir12
           |
           ------dir121
dir2

I want to create new directories like this:

 dir1
  |
  -------dir11
  |        |
  |        -------new
  |
  -------dir12
  |        |
  |        ------dir121
  |        |        |
  |        |        ---------new
  |        |
  |        ------new
  |
  -------new

dir2
  |
  -------new

Is it possible?

find . -type d ! -name "*new*" -exec mkdir {}/new \;

find all folders. make a folder in that folder called new. don't make folders in folders that have new in the same (otherwise it'll get dir1/new/new/new/new, etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM