A search with locate
finds paths in the filesystem.
Often, you know a priori you are interested in either files only, or directories only.
A 'locate' search often returns many results. It would be useful to include only one of the types in the result, because it helps shorten the output.
But there is a more interesting argument to leave out either files or directories: because the list of result paths can be ambiguous - not only in theory.
The example below is a real world case, and not unusual:
$ locate --regex --basename "xfce4-keyboard-overlay$"
/usr/local/bin/xfce4-keyboard-overlay
/usr/local/share/xfce4-keyboard-overlay
Ok, we found something! But... files, or directories?
$ file /usr/local/bin/xfce4-keyboard-overlay
/usr/local/bin/xfce4-keyboard-overlay: bash script
So that is a file...
$ file /usr/local/share/xfce4-keyboard-overlay
/usr/local/share/xfce4-keyboard-overlay: directory
while the second is not.
This ambiguity is making long lists of paths hard to read, so it would be really nice to filter directories out, for example using a comman line option for locate
.
Does something like this exist? Even if the filter for directories is separate from locate?
At least, one could use a script to iterate all the file names to check - which may be slow.