Locand – AND Search with Locate

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.


To find every file with the words “release” and “lsb” in name:

$ locand release lsb
nice -n 2  locate -i -- release | grep -i -- lsb


If you want to use it all the time, you can alias it

$ alias l='locand'
$ l foo bar

To make the alias permanent, put it in your .bashrc.


#!/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] ...] "
	except KeyboardInterrupt:
		print "Exiting on user request..."
if __name__ == '__main__':

Posted in Old Site | Tagged , , , , , , | Comments Off on Locand – AND Search with Locate

Comments are closed.