最近遇到個棘手問題
linux的備份目錄名帶空格,普通處理時,for循環默認會以空格為分隔符遍歷,這就尷尬了
解決關鍵點:
使用find 配合xargs
知識點:
xargs 的 -0 參數與 find 命令
find
命令有一個特別的參數-print0
,指定輸出的文件列表以null
分隔。然后,xargs
命令的-0
參數表示用null
當作分隔符。
$ find /path -type f -print0 | xargs -0 rm
再配合xargs的-L參數那就更穩妥了
如果標准輸入包含多行,-L
參數指定多少行作為一個命令行參數。
$ find /path -type f -print0 | xargs -L1 -0 rm