Tuesday, September 15, 2009

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

No comments:

Post a Comment