Table of Contents
Locand – AND Search with Locate
Search for files whose names contain all search terms.
Requires locate so only works on Linux and other POSIX systems. Tested with Ubuntu Gutsy.
Example
To find every file with the words “release” and “lsb” in name:
$ locand release lsb nice -n 2 locate -i -- release | grep -i -- lsb /var/lib/dpkg/info/lsb-release.list /var/lib/dpkg/info/lsb-release.postinst /var/lib/dpkg/info/lsb-release.md5sums ...
Alias
If you want to use it all the time, you can alias it
$ alias l='locand' $ l foo bar /home/tero/foobar ...
To make the alias permanent, put it in your .bashrc.
Source
#!/usr/bin/env python # locand - Locate files whose name contains all search terms, case insensitive. # (c) 2008 Tero Karvinen http://www.iki.fi/karvinen import subprocess import sys, os def locandPrint(terms): cmd="nice -n 2 " cmd+=" locate -i -- "+terms[0] for term in terms[1:]: cmd += " | grep -i -- "+term print cmd p = subprocess.call(cmd, shell=True) return True def main(): if len(sys.argv)<2: # name of this command counts as one print "Usage: locand term1 [term2 [term3] ...] " sys.exit(os.EX_USAGE) try: locandPrint(sys.argv[1:]) except KeyboardInterrupt: print "Exiting on user request..." sys.exit(os.EX_OK) if __name__ == '__main__': main()