M
M
Mikhail Zhukov2020-01-12 14:46:48
linux
Mikhail Zhukov, 2020-01-12 14:46:48

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

6 answer(s)
P
pfg21, 2020-01-12
@pfg21

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.

A
Alexander Karabanov, 2020-01-12
@karabanov

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.

X
xotkot, 2020-01-12
@xotkot

ncdu -1 /path/to/folder/
ncdu -q -1 /path/to/folder/ (2 sec interval)

A
AUser0, 2020-01-12
@AUser0

du -s /path/to/folder/ doesn't give that information?

C
chupasaurus, 2020-01-12
@chupasaurus

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])

H
hint000, 2020-01-13
@hint000

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:
5e1bcdab9e72b622125239.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question