Skip to content

Instantly share code, notes, and snippets.

@cdot65
Created July 15, 2023 13:12
Show Gist options
  • Save cdot65/736a740d965225503756a226c6a1d87c to your computer and use it in GitHub Desktop.
Save cdot65/736a740d965225503756a226c6a1d87c to your computer and use it in GitHub Desktop.
To iterate over all folders in your current directory, and display the sizes of files in each directory sorted by size, you can use the du and sort commands in Bash. The du command estimates file and directory space usage, while sort can sort lines in text files.
#!/bin/bash
for d in */ ; do
echo "Processing directory: $d"
find "$d" -type f -exec du -ah {} \; | sort -rh | head -n 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment