Is it possible to locate a path in the file system like what can be done for file names? For example I want to find all paths in system that include 'foo/bar', which may have the following result:


4 Answers 4


If you are unable to find the file with the below command then try updatedb for updating db used by locate command.

locate -r foot/bar/


# locate  "/*/bar/avi"

find command can also do this

find / -path */foot/bar*

find / will search the whole system starting from /

  • 2
    locate "*/bar/avi" gave me the fastest and the most accurate result.
    – B Faley
    Jul 13, 2016 at 7:45

using find command,

find . -ipath "*foo/bar*"

or if you prefer regex syntax then you can use,

find . -iregex ".*foo/bar.*"

Try :

ls -lR | sed -n 's/foo\/bar/p' 

Possibly very long output, i d throw it directly in a file

ls -lR | sed -n 's/foo\/bar/p' >> outfile

This should do what you want:

user@machine% find / -print0 | grep -FzZ 'foo/bar'

You'll get a lot of "permission denied" unless you run as root or are running it on your own home directory.

  • 1
    You can also redirect errors with 2>/dev/null
    – Barmar
    Jul 13, 2016 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.