1、需求(删除txt格式的文件)
[root@a1 temp]# ls hello test.txt [root@a1 temp]# find . -type f -name "*.txt" -print | xargs rm -f [root@a1 temp]# ls hello test.txt
2、分析说明
因为很多文件名中都可能会包含空格符,而xargs很可能会误认为它们是定界符(例如,hello test.txt会被xargs误认为是hello和test.txt)
3、结合-print0与find使用,以字符null来分割输出
[root@a1 temp]# find . -type f -name "*.txt" -print0 | xargs -0 rm -f
本文转自 冰冻vs西瓜 51CTO博客,原文链接:http://blog.51cto.com/molewan/1703122,如需转载请自行联系原作者