What is the difference between locate --basename and locate --wholename on Linux?

On the manual page of locate, I read this:

locate --basename
    Match only the base name against the specified patterns. 
    This is the opposite of --wholename.

but I don't get it. What does it mean? What is the difference between locate --basename and locate --wholename? Can you give me some simple examples?


Solution 1:

The basename is the last part of the full path

/etc/default/grub
              ^
             basename

By default locate matches a pattern anywhere in the path.

With -b (basename) it matches only paths where the pattern appears in the last part of the pathname, the filename or directory name itself.

For example, output from locate gimp would include

/etc/gimp
/etc/gimp/2.0
/etc/gimp/2.0/controllerrc

And many other things, but locate -b gimp would find

/etc/gimp

Without including the subdirectories, since there is no gimp string in their basenames.