如何使用命令行删除文件夹中除特定文件类型以外的所有文件

时间:2014-04-16 16:15:14

标签: linux shell command-line command

我在特定文件夹中有很多文件。

我想删除该文件夹中所有期望* .html文件类型的文件。

有没有办法在命令行中执行此操作?我正在使用Linux。

1 个答案:

答案 0 :(得分:2)

我假设您参考linux命令行,如果没有请更新您的问题。

find ./folder/to/look/in -not -iname '*.html' -exec rm {} \; 

Here's an explanation of what this does

修改

如果您没有太多文件,那么您可能希望find执行一个rm命令。您可以使用+代替;

来实现
find ./folder/to/look/in -not -iname '*.html' -exec rm {} +

Here's an explanation of this one