Created
June 9, 2018 22:54
-
-
Save adzhurinskij/fbca62b61275d7f9f9569fac9685c03a to your computer and use it in GitHub Desktop.
Find big size directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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