7

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

B Faley
  • 4,343
  • 11
  • 39
  • 48

4 Answers4

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 /

AReddy
  • 3,172
  • 5
  • 36
  • 76
3

using find command,

find . -ipath "*foo/bar*"

or if you prefer regex syntax then you can use,

find . -iregex ".*foo/bar.*"
Rahul
  • 13,589
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
onlyf
  • 213
  • 1
  • 3
  • 7
-2

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.