How to delete first two lines and last four lines from a text file with bash? March 7, 2023 by Tarik You can combine tail and head: $ tail -n +3 file.txt | head -n -4 > file.txt.new && mv file.txt.new file.txt