Summarize disk usage on Linux
cd /opt/mydir
du -sh *
du -sh * | sort -h
Check free space and compare
FILE_SERVER=/opt/my_file_server # Need at least 17GB x 2 NEED_FREE=$((17224314*2)) FREE_SPACE=$(df -k --output=avail $FILE_SERVER | tail -1 | awk '{print $1}') echo "INFO: Check if free space can not store more than 2 x 17GB" if (( $FREE_SPACE < $NEED_FREE )); then echo "INFO: Free sapce is not enough" echo "INFO: Finding old directories which are stored more than 20 days" for old_dir in $( find $FILE_SERVER -maxdepth 1 -type d -name 'DIR_NAME*' -mtime +20 | sort ); do echo "Removing $old_dir" rm -rf $old_dir done else echo "INFO: Free sapce is enough" fi
Loading