cd /home/usr/bin/logs
find . -mtime +1 -print | sed -n -e '/\.\/arc/d' -e 's/.*\//' -e '/*.[0-9]$/p' | while read i
do
if [-f arc/$i]
then
cat $i >> arc/$i
rm $i
else
mv $i arc
fi
done
Die Protokolldateien liegen in verschiedenen Formaten vor, z. B. „valid.app5s.log.1019, app5s.gf3sts.1019, valid.app5s.gf3log.1019, app5s.gf3log.1019, app5s.gf1sts.1019,valid.app5s.gf1log.1019, app5s.sts.1019“.
Aber ich konnte damit nichts anfangen. Bitte helfen Sie mir, das Problem zu lösen.
Antwort1
Sofern ich nichts übersehen habe, können Sie einfach Folgendes verwenden find
:
find . -maxdepth 1 -mtime +1 -type f -exec mv {} arc/ \;
Dadurch werden alle Dateien im aktuellen Verzeichnis gefunden, die älter als einen Tag sind, und in das Verzeichnis „arc“ verschoben.
Antwort2
Verwenden Sie maxdepth im Suchbefehl
cd /home/usr/bin/logs
find . -maxdepth 1 -mtime +1 -print | while read i
do
if [ -f arc/$i ]
then
cat $i >> arc/$i
rm $i
else
mv $i arc
fi
done