2012年5月17日 星期四

find .. then cd to it(them)

找到含 .git 的目錄,cd 過去,run git status..

ref: http://www.linuxquestions.org/questions/programming-9/shell-script-to-cd-into-the-result-of-find-592503/

#/bin/sh find . -type d -name '.git' | while read F; do D=$F/../ cd "$D" echo $PWD git status cd - > /dev/null echo --------------- done 找到的 path 含 .git,所以要cd 到 .git 上一層。
做完後,回到剛剛的目錄: cd - 不要把 cd - 的 command 印(echo) 出來,所以加上 > /dev/null