Answer the question
In order to leave comments, you need to log in
How to calculate the size of a folder in real time?
Hello.
There are several directories with thousands of files. When using du with different keys, one way or another, you have to wait until the end of processing . This is inconvenient, because in Windows the system will start counting the volume and number of files in real time and you already get the right impression about the contents of the folder, that information may already be enough. You can already make a decision, dig further and so on. How to do something like this on the Linux command line?
Answer the question
In order to leave comments, you need to log in
connect to inotify. but all changes in the file system are passed to it.
filter the stream by necessary paths and actions and then reread the status of changed files.
get the size of catalogs online.
ncdu - wait once (not at all long even if there are thousands of files) and then visually see where what and how much, and then conveniently delete it from there.
32-line counter emulator in Explorer.exe in Python. It reads everything indiscriminately, so it is not recommended to direct it to /dev and other block devices :)
#!/usr/bin/python3
import os,sys
sumSizes = 0
countFiles = 0
countDirs = 0
def reDraw(size):
global sumSizes
sumSizes += size
outString = '\r{0} bytes total, {1} directories and {2} files...'.format(sumSizes, countDirs, countFiles)
print(outString, end='')
def getSizeRecursively(path):
global countDirs
global countFiles
try:
for entry in os.scandir(path):
if not entry.is_dir(follow_symlinks=False):
countFiles += 1
try:
reDraw(entry.stat().st_size)
except:
continue
else:
countDirs +=1
reDraw(entry.stat(follow_symlinks=False).st_size)
getSizeRecursively(entry.path)
except OSError:
pass
getSizeRecursively(sys.argv[1])
The question should be corrected, you want statistics on the thickest folders, but you are asking something completely different. Good answers about ncdu. I will add another option with the GUI, this is baobab . Very clearly, move the mouse over different sectors and see hints:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question