Python in Action: Search for big file in Linux
Here is the codes. Hope that you will love it.
import os
def search():
filesize = 0
filename = ''
for root, dirs, files in os.walk('/'):
for f in files:
f = os.path.join(root, f)
if os.path.isfile(f):
if os.path.getsize(f) > filesize:
filesize = os.path.getsize(f)
filename = os.path.getrealpath(f)
print "file: %s ==> size: %s" % (filename, filesize)
else:
break
if __name__ == '__main__':
search()
No comments:
Post a Comment