【问题标题】:search files in current directory whose name do not contain "txt" in linux在linux中搜索当前目录中名称不包含“txt”的文件
【发布时间】:2015-06-15 14:00:59
【问题描述】:

我知道如何在当前目录中查找后缀为.txt的文件: find *.txt

如何反转这个?

我是 Linux 新手,所以请帮忙。谢谢!

【问题讨论】:

  • @John1024:你可能在想find -name '*.txt'find *.txt,由于使用 unquoted glob,将仅匹配 current 目录中的 *.txt 文件(因为它是 shell 执行globbing),并将匹配的文件作为参数传递给find(假设有*.txt 目录find 递归到它们中,列出所有文件)。
  • @mklement0 你是对的。

标签: linux shell find-util


【解决方案1】:

如果你只想要当前目录,而你的 shell 是 bash:

shopt -s extglob
ls !(*.txt)

reference

【讨论】:

    【解决方案2】:

    在当前文件中查找不是递归的

    find -maxdepth 1 ! -name "*.txt"
    

    【讨论】:

    • @NickKitto:对我来说似乎是一个有效的答案;是什么让你觉得不是?
    【解决方案3】:
    find ! -name  "*.txt"
    

    find -not -name "*.txt"
    

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 2014-01-31
      • 2013-10-30
      • 1970-01-01
      • 2021-12-02
      • 1970-01-01
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多