Skip to content

Instantly share code, notes, and snippets.

@adzhurinskij
Created June 9, 2018 22:54
Show Gist options
  • Save adzhurinskij/fbca62b61275d7f9f9569fac9685c03a to your computer and use it in GitHub Desktop.
Save adzhurinskij/fbca62b61275d7f9f9569fac9685c03a to your computer and use it in GitHub Desktop.
Find big size directories
#!/usr/bin/env python2
import os
import argparse
def argv_parse():
parser = argparse.ArgumentParser(
add_help=True,
description='Find big dirrectories',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('path', action="store", type=str, help='Path')
return parser.parse_args()
def find_dir(dir):
path = os.path.realpath(dir)
for name in os.walk(path).next()[1]:
dirpath = os.path.join(path, name)
dirsize = os.path.getsize(dirpath)
if os.path.islink(dirpath):
continue
if dirsize < 1000000: # 1Mb
find_dir(dirpath)
else:
print '{} - {} bytes'.format(dirpath, dirsize)
def main():
args = argv_parse()
find_dir(args.path)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment