4

Sorry, this question is going to be total newb factor. How do I search within a particular directory using the locate command?

The following command isn't working for me:

# locate -i mnt/external/Songs/"tangerine"

I would like to search within the "Songs" folder.

  • Besides the answer @enzotib gave you can also grep the output from locate: locate tangerine | grep mnt/external/Songs * if you want to look for tangerine that includes mnt/external/Songs – Rinzwind Sep 14 '11 at 11:10
5

Maybe you want

locate -ir 'mnt/external/Songs/.*tangerine'

-r is for regular expressions search, like in grep. You may also use plain globs for situations as simple as this:

locate /mnt/external/Songs/*tangerine*
  • Thank you enzo. I prefer the second line of code you provided because I can autocomplete with tab – user784637 Sep 16 '11 at 2:23
1

Give the find command a try

find /mnt/external/Songs/ -iname tangerine*

Example: I wanted to search for songs with the word concerto in their filename in my Music folder, so :

  nits@nits-workstation:~$ find /mnt/Storage_1/Music/ -iname *concerto*

Output:

/mnt/Storage_1/Music/Music I/Antonio Vivaldi - The Four Seasons and Violin Concertos
/mnt/Storage_1/Music/Music I/Antonio Vivaldi - The Four Seasons and Violin Concertos/10. Concerto No. 4 In F Minor, Rv 297 'winter' - I Allegro Non Molto.mp3
/mnt/Storage_1/Music/Music I/Antonio Vivaldi - The Four Seasons and Violin Concertos/01. Concerto No. 1 In E, Rv 269 'spring' - I Allegro.mp3

This is a nice tutorial for the find command.

  • Is there any way we can do this with locate? Find is super slow on my external =( – user784637 Sep 14 '11 at 11:03
  • This article is good too! help.ubuntu.com/community/find – user784637 Sep 14 '11 at 11:04
  • @LedZeppelin: Agreed , community documentation is the best. For the locate command look at entozib's answer below. – Nitin Venkatesh Sep 14 '11 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.