using SED command to truncate large trace/log files

In production environment we have to maintain trace files of past 15/30/45 days

depending on the retention period, so if we see a log/trace file consuming more space

then instead of deleting that file you might wanna truncate the file and retain only latest ‘N’ number of lines. one good way to do this is by using ‘SED’ utility.

for example:

oracle@accord:/n01/oraflash1> ls
oracle@accord:/n01/oraflash1> du -sh *
445M logsweep_ora_201603.log
oracle@accord:/n01/oraflash1> sed -i -e :a -e ‘$q;N;8000,$D;ba’ logsweep_ora_201603.log
oracle@accord:/n01/oraflash1> du -sh logsweep_ora_201603.log
804K logsweep_ora_201603.log



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s