Tuesday, September 15, 2009

Percent of memory used in a Mount point

dirsize=`df -k $src | tail -1 | awk '{print substr($4, 1, length($4) -1);}'`

Removing n Oldest files in a Unix/Linux mount point

To remove the oldest files even though they lie in multiple directories

files=`find /var/share/temp/ \( ! -regex '.*/\..*' \) -type f -exec stat -c "%y %n" {} \; | sort | head -5 | tr -s ' ' ' ' | cut -d' ' -f4 "$@" `

for file in $files
do
rm -f ${file}
done