Created
October 30, 2015 17:35
-
-
Save jeffThompson/4db15b992aa2926a7ee5 to your computer and use it in GitHub Desktop.
Gets a list of files that don't belong to my user.
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
''' | |
WHICH FILES ARE MINE? | |
Jeff Thompson | 2015 | www.jeffreythompson.org | |
''' | |
import os, pickle, pprint | |
folder = '/' | |
my_uid = 501 | |
not_mine = {} | |
files_walked = 0 | |
files_found = 0 | |
# WHO ARE WE? WHAT ARE WE DOING? | |
os.system('cls' if os.name=='nt' else 'clear') | |
print "FILES THAT AREN'T MINE" | |
print 'Reading from:', folder | |
print 'Ignoring UID:', my_uid | |
# LOOK AT EVERYTHING | |
print '\nWalking all files\n(may take a while!)...' | |
for root, dirs, files in os.walk(folder): | |
for f in files: | |
files_walked += 1 | |
if files_walked % 100000 == 0: | |
print '-', files_walked, 'files' | |
try: | |
full_path = os.path.join(root, f) | |
stats = os.stat(full_path) | |
except: | |
continue | |
uid = stats[4] | |
if uid != my_uid: | |
files_found += 1 | |
if uid in not_mine.keys(): | |
not_mine[uid].append(full_path) | |
else: | |
not_mine[uid] = [ full_path ] | |
print 'Finished!' | |
# RESULTS | |
print '\nFiles walked:', files_walked | |
print 'Files found: ', files_found | |
percent_mine = (float(files_found)/float(files_walked)) * 100 | |
print 'Percent mine:', "%.2f" % percent_mine, '%' | |
# WRITE TO FILE | |
print '\nWriting data to file...' | |
with open('NotMine.pkl', 'wb') as f: | |
pickle.dump(not_mine, f) | |
print '\nALL DONE!\n\n' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment