How to cat/print a file except the last 2 lines

awkbashsedshunix

How can get I get the contents of a text file, except the last (for instance) 2 lines, with standard or GNU shell tools? (bash, tail, cat and so on.)

Best Answer

Use the head command from coreutils:

head -n -2

See info head for more.