I made the mistake of copying the same files to different partitions with good intentions of pruning (deleting) them from the source or target(s) later. Now when I try to locate them I get too many results from locate
command:
rick@alien:~$ locate "display-auto-brightness"
/etc/cron.d/display-auto-brightness
/home/rick/Pictures/display-auto-brightness conky.png
/home/rick/Pictures/display-auto-brightness systray.png
/home/rick/Pictures/display-auto-brightness-config 1.png
/home/rick/Pictures/ps display-auto-brightness.png
/lib/systemd/system-sleep/display-auto-brightness
/mnt/e/etc/cron.d/display-auto-brightness
/mnt/e/lib/systemd/system-sleep/display-auto-brightness
/mnt/e/usr/local/bin/display-auto-brightness
/usr/local/bin/display-auto-brightness
The locate
command is automatically placing the *
wild card after the search string and returning extra undesired results. The .png
files should not be returned.
Why is locate
returning too many results?
Best Answer
That is the default behaviour of
locate
. Seeman locate
:To match only against the filename, explicitly set a glob in the path component:
Or use a regex and the
--basename
option for matching an exact filename:Or, given the results you have shown, you could get away with just asking for paths that contain
display-auto-brightness
at the end:I'll leave it you to use this in a script looping over each filename in a directory.