1

The following is working as inteded:

$ locate */synse_*_r_unseen_zs.npy 
/mnt/home/dario/temp/synse_resources/language_modelling/repo_test_cadavae_5_r_val/bert/cadavae_5_r_unseen_zs.npy                                                                                                   /mnt/home/dario/temp/synse_resources/language_modelling/repo_test_synse_10_r_val/bert/synse_10_r_unseen_zs.npy 
$ locate synse_*_r_unseen_zs.npy 

This however, return nothing.

What's up?

EDIT: Debugging:

$ echo */synse_*_r_unseen_zs.npy 
*/synse_*_r_unseen_zs.npy
$ echo /synse_*_r_unseen_zs.npy
/synse_*_r_unseen_zs.npy
$ echo synse_*_r_unseen_zs.npy
synse_*_r_unseen_zs.npy
WurmD
  • 111
  • 1
    What do echo */synse_*_r_unseen_zs.npy and echo /synse_*_r_unseen_zs.npy output? – muru May 24 '21 at 13:51
  • @muru , nothing illuminating – WurmD May 24 '21 at 15:04
  • is the database up to date? – Rinzwind May 24 '21 at 15:10
  • 2
    Note that you should really wrap these arguments with single quotes to stop the shell from interpreting the asterisk before passing along the arguments to the locate command. For example, do this: locate 'foo*bar', not this: locate foo*bar – Flimm May 24 '21 at 16:04
  • I'm not at a terminal right now, but I've seen similar before, the /filename might be searching for that file with an asterisk as part of the name (ie verbatim), or that file only in the root dir, but the * at the beginning tells it to use wildcard mode, try specifying the mode; or remove the preceding /. – pbhj May 24 '21 at 16:04

2 Answers2

3

When locating files a locate command that contains standard wildcards (also known as globbing patterns) is looking for paths to files in its local database. /synse_*_r_unseen_zs.npy is not a complete path to a file, so locate /synse_*_r_unseen_zs.npy returns nothing (because the search results of locate synse_*_r_unseen_zs.npy in your Ubuntu are an empty set), however */synse_*_r_unseen_zs.npy is a complete path to file(s), so locate */synse_*_r_unseen_zs.npy returns the results of the command. The asterisk character in these commands is interpreted by locate as a wildcard. The asterisk can represent any number of characters (including zero, in other words, zero or more characters).

karel
  • 114,770
  • 2
    It might also be worth noting that if the string doesn't contain any wildcard characters, then locate implicitly adds a leading and trailing * – steeldriver May 24 '21 at 18:45
  • Txs so much for your answer, but I had an important typo in my question. The bafflingness I would like explained is why locate synse_*_r_unseen_zs.npy is not returning anything – WurmD May 24 '21 at 20:45
0

As @steeldriver mentioned, locate by default attaches a * wildcard to the beginning and end of the search term (so locate abc is actually locate *abc*) except when you add a wild card yourself to the search term, then it does not append nor prepend the extra * wild cards.

So, while $ locate synse_*_r_unseen_zs.npy finds nothing because it's not prepending a * to the search term, $ locate *synse_*_r_unseen_zs.npy finds the expected

/mnt/home/dario/temp/synse_resources/language_modelling/repo_test_cadavae_5_r_val/bert/cadavae_5_r_unseen_zs.npy                                                                                                   /mnt/home/dario/temp/synse_resources/language_modelling/repo_test_synse_10_r_val/bert/synse_10_r_unseen_zs.npy 
WurmD
  • 111