Be myself :: 'tool' 카테고리의 글 목록

달력

32024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'tool'에 해당되는 글 1건

  1. 2015.08.12 특정 문자열 파일 찾기 2

특정 문자열을 가진 파일찾는 프로그램이다. 특정 함수의 상수 값을 확인 할 때 소스코드 위치 찾는게 너무 물편해서 간단히 만들어 봤다.
os.walk("/usr") 여기서 "/usr" 부분의 디렉토리만 바꾸면 다른 디렉토리를 중심으로 재귀적으러 traversal 하면서 찾아간다.


FindString.py



import os
import sys
import optparse

def FindString(msg,verbos):
	ResultFile = open("result","w")
	for (path,dirname,files) in os.walk("/usr"):
		for filenames in files:
			try:
				if verbos:
					print "[*]check "+path+"/"+filenames
				f = open(path+"/"+filenames,"r")
				buf = f.read()
				f.close()
				if msg in buf:
					ResultFile.write(path+"/"+filenames+"\n")
					print "[*]find "+path+"/"+filenames
			except:
				continue 

	ResultFile.close()

def main():
	parser = optparse.OptionParser(usage="FindString.py "+"-v True "+"Searc_String")
	parser.add_option("-v",dest="Vervos",type="string",help="Dicide whether print detail or not")

	(options,args) = parser.parse_args()
	if(len(args) == 0):
		print parser.usage
		return
	FindString(args[0],options.Vervos);	


if __name__ == '__main__':
	main()


Posted by flack3r
|