這篇文章主要介紹了 Linux之刪除帶有空格的文件(不是目錄),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。 |
大家平時(shí)工作中對(duì)不帶空格的文件接觸較多。這樣一來刪除操作也是比較簡單的。但是有時(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]#
接下來我們演示刪除帶有空格的文件
[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而非空格間隔的輸入流。
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。
原文來自: /tupian/20230522/
分享題目:Linux之刪除帶有空格的文件-創(chuàng)新互聯(lián)
網(wǎng)站路徑:http://aaarwkj.com/article8/gijop.html成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、微信小程序、網(wǎng)站導(dǎo)航、企業(yè)建站、ChatGPT、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容