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而非空格间隔的输入流。
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· Ollama系列05:Ollama API 使用指南
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率