How can I search a file by its name and partial path?
Pass in a *
wildcard to indicate a match for anything. You also need to escape the *
s, e.g.:
find . -path \*content/docs/file.xml
or enclose the pattern in quotes, e.g.:
find . -path "*content/docs/file.xml"
As the man page describes it:
$ find . -name *.c -print
find: paths must precede expression
This happens because *.c has been expanded by the shell resulting in find actually receiving a command line like this:
find . -name bigram.c code.c frcode.c locate.c -print
That command is of course not going to work. Instead of doing things this way, you should enclose the pattern in quotes or escape the wild‐ card:
$ find . -name \*.c -print
find has a -path
(or the equivalent but less portable -wholename
) option too find $top_dir -wholename *string*
find /usr -path *in/abiw*
>/usr/bin/abiword
find . -type f | grep "content/docs/file.xml"
or just
locate content/docs/file.xml