Skip to main content
Tweeted twitter.com/StackUnix/status/663373765183725568
format, re-tag
Source Link
don_crissti
  • 85.7k
  • 31
  • 234
  • 262

I have a directory tree that I want to search recursively for all files of a certain type (for example all .jpg's.jpg's), but I only want to list these files if they are at the bottom of a directory tree.

As an example if my tree looks like:

 home root f1 f2 f3 f11 f22 f33 f111 f222 f333 

and all folders have .jpg's.jpg's, I only want to list the .jpg's.jpg's in f111f111/f222f222/f333f333, and so on, and ignore the ones in the higher up folders.

I know that I can use a find command (like find . -name "*.jpg"find . -name "*.jpg") to get a listing of all .jpg's.jpg's in the entire tree, but I'm not sure how to limit it to only the bottom most folders without doing something like grep'inggrep'ing the results to filter for 111111/222222/333's333's which isn't really feasible as I have hundreds of folders and I don't know what the last level folders might be named for all of them individually.

I have a directory tree that I want to search recursively for all files of a certain type (for example all .jpg's), but I only want to list these files if they are at the bottom of a directory tree.

As an example if my tree looks like:

 home root f1 f2 f3 f11 f22 f33 f111 f222 f333 

and all folders have .jpg's, I only want to list the .jpg's in f111/f222/f333, and so on, and ignore the ones in the higher up folders.

I know that I can use a find command (like find . -name "*.jpg") to get a listing of all .jpg's in the entire tree, but I'm not sure how to limit it to only the bottom most folders without doing something like grep'ing the results to filter for 111/222/333's which isn't really feasible as I have hundreds of folders and I don't know what the last level folders might be named for all of them individually.

I have a directory tree that I want to search recursively for all files of a certain type (for example all .jpg's), but I only want to list these files if they are at the bottom of a directory tree.

As an example if my tree looks like:

 home root f1 f2 f3 f11 f22 f33 f111 f222 f333 

and all folders have .jpg's, I only want to list the .jpg's in f111/f222/f333, and so on, and ignore the ones in the higher up folders.

I know that I can use a find command (like find . -name "*.jpg") to get a listing of all .jpg's in the entire tree, but I'm not sure how to limit it to only the bottom most folders without doing something like grep'ing the results to filter for 111/222/333's which isn't really feasible as I have hundreds of folders and I don't know what the last level folders might be named for all of them individually.

Source Link

How can I list all files, but only in directories that have no subdirectories?

I have a directory tree that I want to search recursively for all files of a certain type (for example all .jpg's), but I only want to list these files if they are at the bottom of a directory tree.

As an example if my tree looks like:

 home root f1 f2 f3 f11 f22 f33 f111 f222 f333 

and all folders have .jpg's, I only want to list the .jpg's in f111/f222/f333, and so on, and ignore the ones in the higher up folders.

I know that I can use a find command (like find . -name "*.jpg") to get a listing of all .jpg's in the entire tree, but I'm not sure how to limit it to only the bottom most folders without doing something like grep'ing the results to filter for 111/222/333's which isn't really feasible as I have hundreds of folders and I don't know what the last level folders might be named for all of them individually.