#!/usr/bin/python # -*- coding: utf-8 -*- # easy-find # Author: DarkRanger # Version: 20151014 # License: GNU General Public License # History: # 20151014: # * Add "--" to the grep command, to avoid the error when the keyword begins with # a hyphen-minus "-". # 20150905: # * Initial release. import os, sys HELP = '''easy-find - A very simple wrapper for "locate", "find" and "grep" commands Author: DarkRanger Usage: First, you have to use cd(change directory) command manually, to go to the directory where you want to find something in there. Then, find matching files by "find" command: $ fast-find.py -f Or, find matching files by "grep" command: $ fast-find.py -t If no option specified, "locate" command will be called instead: $ fast-find.py ''' def easy_find(): path = os.getcwd() cmd = "" if len(sys.argv) >= 2: if len(sys.argv) >= 3: if sys.argv[1] == "-f": cmd = "find %s -name \"*%s*\"" % (path, sys.argv[2]) if sys.argv[1] == "-t": cmd = "grep -Flr -- \"%s\" %s/*" % (sys.argv[2], path) else: cmd = "locate %s/*%s*" % (path, sys.argv[1]) if cmd != "": #print(cmd) os.system(cmd) else: print(HELP) if __name__ == "__main__": easy_find()