6

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:

/home/myname/test/foo/bar/hello
/var/www/site/foo/bar

10

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/

or

# locate  "/*/bar/avi"
/foot/bar/avi

find command can also do this

find / -path */foot/bar*

find / will search the whole system starting from /

  • 1
    locate "*/bar/avi" gave me the fastest and the most accurate result. – Meysam Jul 13 '16 at 7:45
3

using find command,

find . -ipath "*foo/bar*"

or if you prefer regex syntax then you can use,

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

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
-1

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 '16 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.