使用find命令但排除两个目录中的文件 [英] Use find command but exclude files in two directories
本文介绍了使用find命令但排除两个目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想查找以 _peaks.bed
结尾的文件,但排除 tmp
和 scripts
文件夹。
我的命令是这样的:
find。 -type**!-name* scripts *\)
但是没有奏效。 tmp
和脚本
文件夹中的文件仍然会显示。
find。 -type f -name* _peaks.bed! -path./tmp/*! -path./scripts/*
解释:
-
find。
- 从当前工作目录开始查找(默认为递归) -
-type f
- 指定为find
li>
-
-name* _peaks.bed
- 查找名字以_peaks.bed
-
! -path./tmp / *
- 排除路径以./ tmp /
-
! -path./scripts / *
- 同样排除路径以./ scripts /
开头的所有结果
测试解决方案:
$ mkdir abcde
$ touch a / 1 b / 2 c / 3 d / 4 e / 5 e / ae / b
$ find。型f! -path./a/*! -path./b/*
./d/4
./c/3
./e/a
./e/b
./e/5
您非常接近, - name
选项仅考虑基本名称,其中 -path
考虑整个路径=)
I want to find files that end with _peaks.bed
, but exclude files in the tmp
and scripts
folders.
My command is like this:
find . -type f \( -name "*_peaks.bed" ! -name "*tmp*" ! -name "*scripts*" \)
But it didn't work. The files in tmp
and script
folder will still be displayed.
Does anyone have ideas about this?
解决方案
Here's how you can specify that with find
:
find . -type f -name "*_peaks.bed" ! -path "./tmp/*" ! -path "./scripts/*"
Explanation:
find .
- Start find from current working directory (recursively by default)-type f
- Specify tofind
that you only want files in the results-name "*_peaks.bed"
- Look for files with the name ending in_peaks.bed
! -path "./tmp/*"
- Exclude all results whose path starts with./tmp/
! -path "./scripts/*"
- Also exclude all results whose path starts with./scripts/
Testing the Solution:
$ 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
You were pretty close, the -name
option only considers the basename, where as -path
considers the entire path =)
这篇关于使用find命令但排除两个目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文