Skip to content

Instantly share code, notes, and snippets.

@indrayam
Last active December 11, 2016 23:07
Show Gist options
  • Save indrayam/f801b6f3881b3ccf40b272a92a2079e8 to your computer and use it in GitHub Desktop.
Save indrayam/f801b6f3881b3ccf40b272a92a2079e8 to your computer and use it in GitHub Desktop.
Unix command to find the top 10 files and folders recursively inside a Unix folder
# These commands will ONLY work if you are using GNU 'du', 'find' and 'sort' commands
# Top 10 files by recursively diving inside the current folder (skip .git and .svn folders)
find . -type d \( -iregex ".*git" -o -iregex ".*svn" \) -prune -o -type f -exec du -Sh {} + | sort -rh | head -n 10
# Top 10 files by recursively diving inside the current folder (without skipping any folders)
find . -type f -exec du -Sh {} + | sort -rh | head -n 10
# Top 10 directories by recursively diving inside the current folder (skip .git and .svn folders)
du -Sh --exclude=".git" --exclude=".svn" | sort -rh | head -n 10
# Top 10 directories by recursively diving inside the current folder (without skipping any folders)
du -Sh | sort -rh | head -n 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment