Skip to content

Instantly share code, notes, and snippets.

@AdrianTP
Last active August 29, 2015 14:02
Show Gist options
  • Save AdrianTP/d1de12a271bee861ec7e to your computer and use it in GitHub Desktop.
Save AdrianTP/d1de12a271bee861ec7e to your computer and use it in GitHub Desktop.
replacement for "locate" command which is capable of easily matching *exact* filenames -- placed here for my reference; I am not claiming credit for this; I did not make it
# Thanks to Dark_Helmet
# http://www.linuxquestions.org/questions/linux-newbie-8/can-i-specify-an-exact-filename-in-%27locate%27-205840/#post1053288
function flocate
{
if [ $# -gt 1 ] ; then
display_divider=1
else
display_divider=0
fi
current_argument=0
total_arguments=$#
while [ ${current_argument} -lt ${total_arguments} ] ; do
current_file=$1
if [ "${display_divider}" = "1" ] ; then
echo "----------------------------------------"
echo "Matches for ${current_file}"
echo "----------------------------------------"
fi
filename_re="^\(.*/\)*$( echo ${current_file} | sed s%\\.%\\\\.%g )$"
locate -r "${filename_re}"
shift
(( current_argument = current_argument + 1 ))
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment