
您好,我的目錄中有幾個資料夾。我想在所有這些中執行此命令:
wc -l * > 總計
有沒有辦法讓腳本可以做到這一點?
答案1
是的:
find /YOUR/ROOT/DIR -type f -exec wc -l '{}' \; > total
如果您需要total
每個(子)目錄都有一個文件,那麼您需要循環此呼叫:
find /YOUR/ROOT/DIR -type d | while read
do
# Change '/' to '_' in dir name
NAME=$(echo "$REPLY" | sed -e 's#/#_#g')
wc -l "$REPLY" > "total.$NAME"
done
希望能幫助你。