Last active
November 15, 2022 10:57
-
-
Save janxkoci/29951cfc47b7ed4ad46b981324b3e118 to your computer and use it in GitHub Desktop.
See size of your top 10 largest files and folders.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Takes path as argument ($1) or uses current path instead (.) if no argument given. | |
path="${1:-.}" | |
## Gets size for items in path and reports the top 10 files and folders. | |
du -sh ${path}/* | sort -rh | head -n ${2:-10} |
Update
- I've removed an underscore from the file name so it's easier to call the script with TAB completion.
- I've added a second (optional) parameter to display different number of items. Provide any number.
- Note that if you use this you also need the first parameter, so provide at least a dot
.
for the current folder, e.g.bigfiles.sh . 20
.
- Note that if you use this you also need the first parameter, so provide at least a dot
Evgeny uses the following:
# Use this command in your home dir to locate large files:
find . -type f -size +10G | xargs -I {} ls -sh {}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This simple script shows sizes of top 10 largest files and folders for a given path, or if no path is given for the current path.
The magic is in the
${1:-.}
piece. It is the traditional positional argument$1
, but with a default value.
in case the argument is omitted. I've stolen this trick from this awesome awk tutorial. (It's awesome, because it teaches more thanawk
😉 )