Skip to content
Discussion options

You must be logged in to vote

I really would love to see this in dua, but if you don't add it, here is a shell script I whipped up. Who knows, maybe someone finds it useful.

#!/usr/bin/env bash

# Calculate the size of files in current directory
# (without traversing into subdirectories)

if [[ -z $1 ]]; then
	DIR=.
else
	if [ -d "$1" ]; then
		DIR="$1"
	else
		echo "Error: not a directory"
		exit 1
	fi
fi

if [[ "$(uname -s)" == "Darwin" ]]; then
	OPT=-f%z
else
	OPT=-c%s
fi

OIFS="$IFS"
IFS=$(echo -en "\n\b")

DIR_SIZE_BYTES=$(
for i in `find $DIR -maxdepth 1 -type f`
do
	stat $OPT "$i"
done |paste -sd+ - |bc
)
IFS="$OIFS"

[[ -z $DIR_SIZE_BYTES ]] && DIR_SIZE_BYTES=0
DIR_SIZE=$DIR_SIZE_BYTES

UNITS='B KB MB GB TB PB EB

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@tessus
Comment options

@Byron
Comment options

Byron Feb 7, 2026
Maintainer

@tessus
Comment options

@tessus
Comment options

Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants