09-29-2020, 06:22 AM
To find Largest Top 10 directories which is using most of Disk Space on your System
#!/bin/bash
for i in G M K
do
du -ah | grep [0-9]$i | sort -nr -k 1
done | head -n 11
# du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
# du command -s option : show only a total for each argument (summary).
# du command -x option : skip directories on different file systems.
# sort command -r option : reverse the result of comparisons.
# sort command -h option : compare human readable numbers. This is GNU sort specific option only.
# head command -10 OR -n 10 option : show the first 10 lines.
Creating an Alias for finding most Disk usages :
vim ~/.bashrc
## shell alias ##
alias ducks='du -ckhs * | sort -rn | head'
## deal with special files names ##
alias ducks='du -ckhs -- * | sort -rn | head'
## Update the Bashrc File
source ~/.bashrc
## Run the Alias
$ducks
#!/bin/bash
for i in G M K
do
du -ah | grep [0-9]$i | sort -nr -k 1
done | head -n 11
# du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
# du command -s option : show only a total for each argument (summary).
# du command -x option : skip directories on different file systems.
# sort command -r option : reverse the result of comparisons.
# sort command -h option : compare human readable numbers. This is GNU sort specific option only.
# head command -10 OR -n 10 option : show the first 10 lines.
Creating an Alias for finding most Disk usages :
vim ~/.bashrc
## shell alias ##
alias ducks='du -ckhs * | sort -rn | head'
## deal with special files names ##
alias ducks='du -ckhs -- * | sort -rn | head'
## Update the Bashrc File
source ~/.bashrc
## Run the Alias
$ducks