linux - 使用 find 命令但排除两个目录中的文件

我想查找以 _peaks.bed 结尾的文件,但排除 tmpscripts 文件夹中的文件。

我的命令是这样的:

 find . -type f \( -name "*_peaks.bed" ! -name "*tmp*" ! -name "*scripts*" \)

但它没有用。 tmpscript 文件夹中的文件仍会显示。

有人对此有想法吗?

最佳答案

您可以通过以下方式指定 find:

find . -type f -name "*_peaks.bed" ! -path "./tmp/*" ! -path "./scripts/*"

说明:

  • find . - 从当前工作目录开始查找(默认递归)
  • -type f - 指定 find 你只希望结果中的文件
  • -name "*_peaks.bed" - 查找名称以 _peaks.bed
  • 结尾的文件
  • ! -path "./tmp/*" - 排除路径以./tmp/
  • 开头的所有结果
  • ! -path "./scripts/*" - 同时排除路径以 ./scripts/
  • 开头的所有结果

测试解决方案:

$ mkdir a b c d e
$ touch a/1 b/2 c/3 d/4 e/5 e/a e/b
$ find . -type f ! -path "./a/*" ! -path "./b/*"

./d/4
./c/3
./e/a
./e/b
./e/5

您非常接近,-name 选项仅考虑基本名称,而 -path 考虑整个路径 =)

https://stackoverflow.com/questions/14132210/

相关文章:

python - 打印两个日期之间的所有日期

python - 在 Python 中使用多个参数进行字符串格式化(例如 '%s ... %s' )

python - linux tee 不能与 python 一起使用?

python - 访问对象内存地址

linux - 如何使用 cURL 从 GitHub 下载 tarball?

python - 如何在被调用的方法中获取调用者的方法名?

linux - 编写一个shell脚本ssh到远程机器并执行命令

python - 如何使用 pandas 读取大型 csv 文件?

windows - 如何确定特定文件是否在 Windows 中打开?

python - Python 的 List 是如何实现的?