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

查看:24
本文介绍了使用 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天全站免登陆