bashoneliners.com

Welcome to bashoneliners.com, a curated collection of practical and well-explained Bash one-liners, snippets, tips and tricks. We aim to make each published one-liner to be of high quality: useful, easy to read, follows best practices, with clear, detailed, accurate explanation. These one-liners should help you automate tasks, troubleshoot problems, whether it be in system administration, file management, networking or programming.

List docker log sizes

docker ps -qa | xargs docker inspect --format='{{.LogPath}}' | xargs sudo du -hl

June 18, 2019lockntross

Sort du output in Human-readable format

du -hsx * | sort -rh

April 26, 2012Vaevictus

Sort du output in Human-readable format

for i in G M K; do du -hsx * | grep "[0-9]$i\b" | sort -nr; done 2>/dev/null

April 14, 2012bashoneliners

Sort du output in Human-readable format

for i in $(echo -e 'G\nM\nK'); do du -hsx /* 2>/dev/null | grep '[0-9]'$i | sort -rn; done

April 14, 2012jasembo

Calculate the total disk space used by a list of files or directories

du -s file1 dir1 | awk '{sum += $1} END {print sum}'

December 28, 2011bashoneliners