How to Display Accurate Directory Sizes in Midnight Commander (Including Subdirectory Calculation)


2 views

Midnight Commander's default directory size display shows only the metadata size (typically 4KB) rather than the actual cumulative size of all contained files. This becomes particularly frustrating when managing directories with numerous empty subfolders or when precise disk space monitoring is needed.

While MC doesn't have built-in real-time directory size calculation, these workarounds exist:

1. Press Ctrl+Space in the active panel to calculate selected directory size
2. Use the 'Quick View' (Ctrl+Q) on a directory
3. Enable 'Show inodes' in Panel Options (but this shows file count, not size)

For persistent directory size display, we can create a shell script and integrate it with MC:

#!/bin/bash
# mc_dirsize.sh - Calculate directory size for MC display
if [ -d "$1" ]; then
    du -sh "$1" | cut -f1
else
    ls -ld "$1" | awk '{print $5}'
fi

Add this to your mc.ext file (usually in /etc/mc/ or ~/.config/mc/):

regex/\.\*
    View=%view{ascii}
    Link=%var{DESTDIR}
    DirectorySize=/path/to/mc_dirsize.sh %f

Be aware that recursive directory scanning (especially via du) can be resource-intensive on large directory trees. For production systems, consider:

  • Caching results for frequently accessed directories
  • Implementing a filesystem watcher to update sizes only when changes occur
  • Setting up a daily cron job to pre-calculate sizes

If directory size visibility is critical, these alternatives natively support accurate size display:

- Ranger (Python-based)
- NNN (C-based, extremely lightweight)
- Krusader (KDE's twin-panel manager)

Midnight Commander (MC) is a powerful file manager for Unix-like systems, but one common frustration is its default behavior of showing directory sizes as "0" or the base size without contents. This becomes particularly problematic when:

  • Managing storage space with many nested directories
  • Identifying large directories for cleanup
  • Comparing directory structures

MC actually has this capability through its Ctrl+Space shortcut. Here's how it works:

1. Navigate to the directory you want to measure
2. Press Ctrl+Space (or Command+Space on macOS)
3. MC will recursively calculate the actual size
4. The size will appear in the "Size" column

For those who want directory sizes to always display accurately, modify your ~/.config/mc/ini file:

[Midnight-Commander]
show_directory_size=1
use_du=1

This tells MC to:

  • Calculate sizes using du (disk usage) command
  • Display the sizes persistently in panels

For power users who need more control over the scanning process, create a custom wrapper script:

#!/bin/bash
# ~/bin/mc_du_wrapper
du -h --max-depth=1 "$@" | sort -h

Then configure MC to use it:

[Midnight-Commander]
external_dir_size_cmd=~/bin/mc_du_wrapper

While recursive size calculation is useful, be aware that:

  • Scanning large directory trees can take significant time
  • Network-mounted directories may respond slowly
  • Frequent rescans impact system performance

For these cases, consider setting show_directory_size=2 which only calculates when explicitly requested.

If directory sizes still don't appear:

1. Verify the panel view mode is set to "Full" (F9 → Left/Right → Listing mode)
2. Check that columns include "Size" (F9 → Panel options → Display columns)
3. Ensure you have read permissions for all subdirectories