[問題] shell的問題請教

看板Linux作者 (呆呆牛)時間14年前 (2011/07/07 17:59), 編輯推噓2(204)
留言6則, 3人參與, 最新討論串1/1
小弟在寫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!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.219.215.93 ※ 編輯: lizardho 來自: 61.219.215.93 (07/07 18:00)

07/07 19:39, , 1F
find . -type f -size 0 -exec ls {} \;
07/07 19:39, 1F

07/07 20:49, , 2F
呃. 為什麼不直接 test -s $file && rm $file
07/07 20:49, 2F

07/07 20:51, , 3F
還有,檔案有沒有空白行?
07/07 20:51, 3F

07/07 22:25, , 4F
你弄反:FILE exists and has a size greater than zero
07/07 22:25, 4F

07/07 22:27, , 5F
改: if [ -f $xxx ]; then test -s $xxx || rm $xxx; fi
07/07 22:27, 5F

07/08 08:32, , 6F
反了耶XD 不過不用test -f吧, 沒有東西,rm也不會怎樣
07/08 08:32, 6F
文章代碼(AID): #1E5OEGRI (Linux)