• Uncategorized

About shell : find-full-path-given-partial-path

Question Detail

I know how to find files using

find . -name "file_name"

But if I am given one part of a path, say “folder1/subfolder2/”, how do I get all the full path that contains this partial path?


partial path: folder1/subfolder2/

desire result:


Question Answer

Use the -path option:

find . -path '*/folder1/subfolder2/*'

You may do it like below:

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

With -prune you don’t recurse after first match in a directory

This one worked for me (using bash)

ls -l /**/folder1/subfolder2/**

I came up with this, other solutions did not work for me,

find1 is a function

find1 ()
    for file in `find -name $1`;
        echo $full_path;

If you dont want to stay posix-compliant, at least on Linux you can also use the -regex (and -regextype) option for this purpose.

For instance:

find folder/ -regextype posix-extended -regex "(.*/)?deer/(.*/)?beer"

will match



See linux man for details.

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.