Suppose a path like
/home/albfan/Projects/InSaNEWEBproJECT
Despite of the fact to not use such that names. Is there a way to check for a path
The simplest solution:
$ find . | grep -qi /path/to/something[^/]*$
But if you have some additional conditions that must be checked for matched file, you can run grep
inside find
:
$ find . -exec sh -c 'echo {} | grep -qi /path/to/something' \; -print
Here you will get all files that are in the directory. If you want to get only the directory's name:
$ find . -exec sh -c 'echo {} | grep -qi /path/to/something[^/]*$' \; -print
Example of usage:
$ mkdir -p Projects/InSaNEWEBproJECT/src/main/resources/
$ find . -exec sh -c 'echo {} | grep -qi /projects/insanewebproject[^/]*$' \; -print
./Projects/InSaNEWEBproJECT
My fault! I guess I tried
find -ipath 'projects/insanewebproject'
but the trick here is that I must use
find -ipath './projects/insanewebproject'
That ./ does the change. Thanks!.
man says -path is more portable than -wholename
if you expect only one result, you can add | head -n1, cause that way head kill pipe when it fills its buffer, which is only one line length
find -ipath './projects/insanewebproject'| head -n1