Skip to main content
deleted 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

(Where pattern is some pattern like *delivery*.tar*proj*.gztgz.)

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding one or several files in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

(Where pattern is some pattern like *delivery*.tar.gz.)

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding one or several files in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

(Where pattern is some pattern like *proj*.tgz.)

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding one or several files in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

added 61 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

(Where pattern is some pattern like *delivery*.tar.gz.)

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding a fileone or several files in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding a file in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

(Where pattern is some pattern like *delivery*.tar.gz.)

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding one or several files in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Prune search tree if file is found

I need to search a rather big directory hierarchy for regular files with names matching a particular filename globbing pattern. The hierarchy is so big (both very deep and with some enormous directories) that it would take far too long to take a naive approach:

find /top/dir -type f -name 'pattern'

Due to the nature of the directory structure, I know I could introduce an optimization to prune the search tree if find found a file in a directory. For example, finding a file in a particular directory would mean that I wouldn't need to examine any of the subdirectories of that specific directory for other matches.

Since applying -prune to a regular file isn't doing the right thing, I can't just do

find /top/dir -type f -name 'pattern' -prune

Question: How do I avoid searching the subdirectories of the directory that contains the file(s) that matches the pattern?