1, the preface
The scenario is simple, for example, I want to delete all files larger than 10M.
2, code,
#! /bin/bash
Delete files larger than 10M from Tomcat /logs
for file in $(ls /home/a/tomcat/logs)
do
if [ -f $file ]; then
if [ $(ls -l $file|awk '{print $5}') -gt 10000 ]; then
# delete file
rm -rf $file
fi
fi
done
Copy the code
Awk ‘{print $5}’ extracts the file size displayed by ls -l and compares it with the specified file size