2017-10-07 69 views
1

我有這個目錄。如何遞歸地去每個文件夾並執行同名的shell腳本?

. 
├── animation 
│   ├── animation-events 
│   │   ├── app.js 
│   │   ├── app.mustache.json 
│   │   ├── create_view.sh 
│   │   └── assets 
│   │    └── dummy_character_sprite.png 
│   └── change-frame 
│    ├── app.js 
│    ├── app.mustache.json 
│      ├── create_view.sh 
│    └── assets 
│     └── dummy_character_sprite.png 
├── app.css 
├── app.mustache 
├── bunch_of_functions.js 
├── decorators.js 
├── create_all_views.sh 
└── displaying-a-static-image 
    ├── app.js 
    ├── app.mustache.json 
    ├── create_view.sh 
    └── assets 
     └── piplup.png 

我要爲create_all_views.sh在孩子目錄中執行所有create_view.sh。我怎麼能做到這樣的事情?

回答

4

正如你在Ubuntu,你有GNU實施find, 它具有-execdir選項, ,你可以這樣做:

find path/to/dir -name create_view.sh -execdir ./create_view.sh \; 

也就是說, 每個create_view.sh文件找到在目錄樹中, 它將在該文件的目錄中執行./create_view.sh

+0

很好,'\;'用於什麼? – notalentgeek

+0

'\;'用於表示參數結束到'-execdir'。例如,你可以在它後面有更多選項,例如'find path/to/dir -name create_view.sh -execdir ./create_view.sh \; -print -ls' – janos

+0

如何執行多個命令?我找到了$(dirname $ 0)-name create_view.sh -execdir chmod + x ./create_view.sh \ ./create_view.sh \;'但是它返回''chmod + x'上沒有這樣的文件或目錄' 。 – notalentgeek

相關問題