2014-01-17 31 views
2

我想從find排除.git文件夾,因爲sed總是破壞git索引文件。我的腳本是:查找 - 文件夾不排除和sed腐敗git索引,因爲它

folder_root="my-files/files" 

# change text in files 
find $folder_root/ -type f -and -not -path $folder_root/.git -print0 | LC_ALL=en_US.CP437 xargs -0 -n 1 sed -i '' -e 's/fromthis/tothis/g' 

,仍然git index得到腐敗:只有

error: bad index file sha1 signature 
fatal: index file corrupt 

回答

0

-path "$theme_root/.git"匹配特定的目錄,而不是目錄中的文件。嘗試代替

find "$folder_root/" -name .git -prune -o -type f -print0 | ... 

-prune行動從下降到一個目錄停止find,所以它會做你想要什麼,並會更快也。