Tail command in one line

HI i have to copy the last 5000 lines form a log file and copy the same in the same file .overwriting the same log file.

ex: tail -5000 testfile1 > testfile2
cat testfile2
mv tesftfile2 testfile1

will produce the correct result.but i want to have this done in one line????

tail -5000 testfile1 > testfile2 && mv tesftfile2 testfile1

Regards

thanks for the solution its working.

but i have one query

when i am giving
tail -5000 testfile1 > testfile1

why on seeing the content by cat tesftile1 it is blank???????:frowning:

Because you are overriding the original file (redirection empties it). Destination should be some temporary file.

Thanks