I need to know the fastest way possible, in PHP or Linux Command Shell, to reduce a text file that has more than 10 lines to only have the last 10 lines. I want to use 10 lines for this example.
Thanks :)
I need to know the fastest way possible, in PHP or Linux Command Shell, to reduce a text file that has more than 10 lines to only have the last 10 lines. I want to use 10 lines for this example.
Thanks :)
to reduce a file to it's last then lines do
tail -n 10 /path/to/file > /path/to/file.tmp && rm /path/to/file && mv /path/to/file.tmp /path/to/file
explanation:
tail
outputs the last n
lines of a file.
>
writes it to a file.
&&
is for chaining commands.
rm
removes a file.
mv
renames a file (or moves to a different location).