shell的問題請教 - Linux

Table of Contents

小弟在寫shell時會產生一些檔案
可是因為比對的關係,有些檔案會是空檔
於是小弟想再額外寫一段shell去刪除空檔

以下是我的程式段
執行後並不會刪除除空檔,想請教正確的寫法
# if file is null then delete
test -s $homedir/log_not_upload > /dev/null
if [ $? -eq 0 ]; then
rm $homedir/log_not_upload
fi

想請教該怎麼改才會刪除檔案
感謝

--

We must not confuse dissent with disloyalty!!

--

All Comments

Zenobia avatarZenobia2011-07-11
find . -type f -size 0 -exec ls {} \;
Annie avatarAnnie2011-07-15
呃. 為什麼不直接 test -s $file && rm $file
Dorothy avatarDorothy2011-07-19
還有,檔案有沒有空白行?
Elizabeth avatarElizabeth2011-07-23
你弄反:FILE exists and has a size greater than zero
Odelette avatarOdelette2011-07-26
改: if [ -f $xxx ]; then test -s $xxx || rm $xxx; fi
Ula avatarUla2011-07-29
反了耶XD 不過不用test -f吧, 沒有東西,rm也不會怎樣