linux/scripts/truncatefiles.sh

19 lines
313 B
Bash

#!/bin/sh
maxsize=$((4*1024*1024))
trnsize=$((2*1024*1024))
folders='/var/log'
IFS=$'\n'
for d in $folders do
cd "$d"
for f in $(find -type f \! -iname '*.[xbgl]z*'); do
if [ $(stat -c %s "$f") -ge $maxsize ]; then
tail -c $trnsize < "$f" | tail -n +2 > "$f.tmp"
cat "$f.tmp" > "$f"
fi
done
done