1
0
mirror of https://github.com/mosbth/cimage.git synced 2025-01-16 18:48:14 +01:00

More examples on dealing with cache through bash bin/cache.bash, #129.

This commit is contained in:
Mikael Roos 2015-12-02 11:04:42 +01:00
parent 8e1318c31e
commit 91ae49b3f3
2 changed files with 26 additions and 18 deletions

View File

@ -8,6 +8,7 @@ Revision history
v0.7.7* (2015-10-25)
-------------------------------------
* More examples on dealing with cache through bash `bin/cache.bash`, #129.
* Added Gitter badge to README, #126.
* Fix proper download url in README, #125.

View File

@ -1,22 +1,17 @@
#!/bin/bash
#
# Specify the utilities used
# ls -ult list and sorts fils by its access time
#
ECHO="printf"
#
# Main, start by checking basic usage
#
if [ $# -lt 1 ]
then
$ECHO "Usage: $0 [cache-dir]\n"
echo "Usage: $0 [cache-dir]"
exit 1
elif [ ! -d "$1" ]; then
$ECHO "Usage: $0 [cache-dir]\n"
$ECHO "$1 is not a directory.\n"
echo "Usage: $0 [cache-dir]"
echo "$1 is not a directory."
exit 1
fi
@ -25,12 +20,24 @@ fi
#
# Print out details on cache-directory
#
$ECHO "Total size: $( du -sh $1 | cut -f1 )"
$ECHO "\nNumber of files: $( find $1 | wc -l )"
$ECHO "\n\nTop-5 largest files:\n"
$ECHO "$( du -s $1/* | sort -nr | head -5 )"
$ECHO "\n\nLast-5 created files:\n"
$ECHO "$( find $1/* -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 )"
$ECHO "\n\nLast-5 accessed files:\n"
$ECHO "$( find $1/* -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort -r | head -5 )"
$ECHO "\n"
echo "# Size"
echo "Total size: $( du -sh $1 | cut -f1 )"
echo "Number of files: $( find $1 -type f | wc -l )"
echo "Number of dirs: $( find $1 -type d | wc -l )"
echo
echo "# Top-5 largest files/dirs:"
echo "$( du -s $1/* | sort -nr | head -5 )"
echo
echo "# Last-5 created files:"
echo "$( find $1 -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r | head -5 )"
echo
echo "# Last-5 accessed files:"
echo "$( find $1 -type f -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort -r | head -5 )"
echo
echo "# 5 Oldest files:"
echo "$( find $1 -type f -printf '%AY-%Am-%Ad %AH:%AM %f\n' | sort | head -5 )"
echo
echo "# Files not accessed within the last 30 days"
echo "Number of files: $( find $1 -type f -atime +30 | wc -l )"
echo "Total file size: $( find $1 -type f -atime +30 -exec du {} \; | cut -f1 | paste -sd+ | bc )"
echo