
我想編寫一個可以刪除所有 0 大小檔案的腳本。我已經有執行此操作的命令 - find . -size 0 -type f -delete
。問題是我想使用第一個腳本參數作為路徑。我有這樣的事情:
#!/bin/bash
$1/$(find . -size 0 -type f -delete)
錯誤:語法錯誤
答案1
使用:
#!/bin/bash
find "$1" -size 0 -type f -delete
您也可以這樣做:
#!/bin/bash
cd "$1" && find . -size 0 -type f -delete