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?
You can try below:
for me, this solution didn't worked on a command exec with find, don't really know why, so my solution is
Explanation: same as sampson-chen one with the additions of
-prune - ignore the proceding path of ...
-o - Then if no match print the results, (prune the directories and print the remaining results)
Try something like
and don't be too surprised if I got it a bit wrong. If the goal is an exec (instead of print), just substitute it in place.
Here is one way you could do it...
Here's how you can specify that with
find
: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:
You were pretty close, the
-name
option only considers the basename, where as-path
considers the entire path =)