使用find和grep删除文件列表 [英] Delete a list of files with find and grep

查看:61
本文介绍了使用find和grep删除文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除所有名称包含特定单词的文件,例如车".到目前为止,我想到了这个:

I want to delete all files which have names containing a specific word, e.g. "car". So far, I came up with this:

find|grep car

如何将输出传递给rm?

How do I pass the output to rm?

推荐答案

find . -name '*car*' -exec rm -f {} \;

或将管道的输出传递给 xargs :

or pass the output of your pipeline to xargs:

find | grep car | xargs rm -f

请注意,这些都是非常钝的工具,您可能会删除不打算删除的文件.另外,在此不做任何处理包含空格(包括换行符)或前导破折号等字符的文件的工作.被警告.

Note that these are very blunt tools, and you are likely to remove files that you did not intend to remove. Also, no effort is made here to deal with files that contain characters such as whitespace (including newlines) or leading dashes. Be warned.

这篇关于使用find和grep删除文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆