Created
April 16, 2023 12:45
-
-
Save amineHY/ff353d4a2f6a3081161ea00bef687f7e to your computer and use it in GitHub Desktop.
This is a bash script that can be used to analyze the disk usage of a directory and its subdirectories.
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 | |
# define the directory to analyze (default is the current directory) | |
DIR=${1:-.} | |
# run the du command to get disk usage information | |
du -ah $DIR | sort -rh | head -n 20 | |
# explain the output | |
echo "" | |
echo "The output shows the top 20 directories and files in $DIR by size." | |
echo "The size is displayed in a human-readable format, and includes the size of subdirectories and files." | |
echo "Directories are shown with a trailing slash (/), and hidden files and directories are included." | |
echo "The -h option is used to display the size in a human-readable format (e.g. 10K, 20M, 2G)." | |
echo "The -a option is used to include all files, including hidden files." | |
echo "The -sort option is used to sort the output by size in reverse order (largest first)." | |
echo "The -n option is used to limit the output to the top 20 results." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment