If i lost a file I use locate a lot. Works perfectly and with grep you can quickly find back what you looked for.

However, often it generates a lot of output which is not always easy to filter. One instance is when searching for a lost dir when the name is used in the base of a lot of entries. Try searching all bin dirs for example.

Locate by itself has no option to only search for directory type entries, but it has a option to parse a regexp. Unfortunately I am no high flyer on regexp.

What would the regexp be to parse to locate to show 1 occurrence of every bin dir, or can I better use a different pipe?

locate -r '/bin$'

will only show paths that end with /bin. As / can't be part of a file name that is files and folders named bin.

  • The trick is in the $, but what does it mean, end of line? – Requist Mar 4 '14 at 14:23
  • 1
    As locate prints one path per line the end of line is the same as the end of the path. That is a /bin not followed by anything – Florian Diesch Mar 4 '14 at 14:31

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.