【问题标题】:How to delete all files expect specific file type in the folder using command line [closed]如何使用命令行删除文件夹中特定文件类型的所有文件[关闭]
【发布时间】:2014-04-16 16:15:14
【问题描述】:

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

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

有没有办法在命令行中做到这一点?我正在使用 Linux。

【问题讨论】:

  • 请添加您的操作系统(windows、mac、linux等)。
  • 这个问题也更适合superuser.com
  • linux操作系统

标签: linux shell command-line command


【解决方案1】:

我假设您参考的是 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

【讨论】:

  • 我喜欢你的解决方案,但不如我喜欢管道。
  • 尽管它不是一个昂贵的资源,但如果没有必要,我发现启动一个额外的程序并创建一个管道有点浪费
  • 我其实不知道-exec。你的答案比我的更正确,因为我做了一些完全没有意义的事情。我刚刚将解释外壳链接添加到您的答案中,我正在删除我的。
猜你喜欢
  • 2012-08-31
  • 2012-07-26
  • 2012-01-02
  • 1970-01-01
  • 2012-12-15
  • 1970-01-01
  • 2019-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多