Hello,

Welcome to Webune.

Webune offers Linux Dedicated Servers.

today we are going to show you how you can empty a file or reduce the file size by deleting all except the last five lines

for example, i have a file called http-error.log in the /var/log/ directory

first start a root session in your shell and cd to the /var/log directory:
SHELL COMMAND:
cd /var/log/


list the files in the /var/log folder:
SHELL COMMAND:
ls -la /var/log/


OUTPUT:
78452115 httpd-error.log


as you can see from the example output, the size of the httpd-error.log is 78452115

now you can use the tail command to delete all but the last file lines
SHELL COMMAND:
tail -5 httpd-error.log > httpd-error.log


now you can ls the files and you will see that all the other lines in the files have been removed
SHELL COMMAND:
ls -la /var/log/


you will notice that the file has been reduced in size

hope that helps