Linux之刪除帶有空格的文件(不是目錄)
更新時間:2020年01月14日 09:40:08 作者:峰哥ge
這篇文章主要介紹了Linux之刪除帶有空格的文件(不是目錄),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
大家平時工作中對不帶空格的文件接觸較多。這樣一來刪除操作也是比較簡單的。但是有時我們會接觸帶有空格的文件。對于這種文件我們應該如何刪除呢?
首先我們演示一下find命令結合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
上面的參數-print0,于默認的-print相比,輸出的序列不是以空格分隔,而是以null字符分隔。而xargs也有一個參數-0,可以接受以null而非空格間隔的輸入流。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Linux jdk安裝及環(huán)境變量配置教程(jdk-8u144-linux-x64.tar.gz)
這篇文章主要介紹了Linux jdk安裝及環(huán)境變量配置(jdk-8u144-linux-x64.tar.gz),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-03-03Linux解決RocketMQ中NameServer啟動問題的方法詳解
這篇文章主要為大家詳細介紹了Linux解決RocketMQ中NameServer啟動問題的方法,文中通過圖片和示例代碼進行了詳細講解,需要的小伙伴可以參考下2023-08-08linux Jenkins配置salve節(jié)點實現(xiàn)過程圖解
這篇文章主要介紹了linux Jenkins配置salve節(jié)點實現(xiàn)過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-08-08