UNIX: how to use the find command to find the full path if a given partial path

I know how to find files using

find . -name "file_name" 

But if I am given one part of the path, say "folder1 / subfolder2 /", how do I get the entire full path containing this incomplete path?

Example

partial path: folder1/subfolder2/

result result:

 /bob/folder1/subfolder2/yo/ /sandy/folder1/subfolder2/hi/ 
+5
source share
3 answers

Use the -wholename parameter instead of -name :

 find FOLDER -wholename '*folder1/folder2/*' 
+7
source

This worked for me (using bash)

 ls -l /**/folder1/subfolder2/** 
+2
source

You can do this as shown below:

 find . -path "*folder1/folder2" -prune -exec find {} -type f -name file.txt \; 

With -prune you do not overwrite after the first match in the directory

+2
source

Source: https://habr.com/ru/post/1247895/


All Articles