Linux之刪除帶有空格的文件(不是目錄)
大家平時(shí)工作中對(duì)不帶空格的文件接觸較多。這樣一來(lái)刪除操作也是比較簡(jiǎn)單的。但是有時(shí)我們會(huì)接觸帶有空格的文件。對(duì)于這種文件我們應(yīng)該如何刪除呢?
首先我們演示一下find命令結(jié)合xargs命令刪除不帶空格的文件
[root@ELK-chaofeng test]# touch 1.txt 2.txt [root@ELK-chaofeng test]# ls 1.txt 2.txt [root@ELK-chaofeng test]# find . -type f | xargs ./1.txt ./2.txt [root@ELK-chaofeng test]# find . -type f | xargs rm -rf [root@ELK-chaofeng test]# ls [root@ELK-chaofeng test]#
接下來(lái)我們演示刪除帶有空格的文件
[root@ELK-chaofeng test]# touch 1.txt 2.txt '1 2.txt' [root@ELK-chaofeng test]# ls 1 2.txt 1.txt 2.txt [root@ELK-chaofeng test]# ll total 0 -rw-r--r-- 1 root root 0 Feb 14 12:24 1 2.txt -rw-r--r-- 1 root root 0 Feb 14 12:24 1.txt -rw-r--r-- 1 root root 0 Feb 14 12:24 2.txt [root@ELK-chaofeng test]# find . -type f -print0 | xargs -0 rm -rf [root@ELK-chaofeng test]# ls
上面的參數(shù)-print0,于默認(rèn)的-print相比,輸出的序列不是以空格分隔,而是以null字符分隔。而xargs也有一個(gè)參數(shù)-0,可以接受以null而非空格間隔的輸入流。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。