1、測試數據
root@PC1:/home/test2# ls a.txt root@PC1:/home/test2# cat a.txt 01 02 03 04 05 06 07 08 09 10
2、head 實現
root@PC1:/home/test2# ls a.txt root@PC1:/home/test2# cat a.txt 01 02 03 04 05 06 07 08 09 10 root@PC1:/home/test2# head -n -3 a.txt ## 刪除最后3行 01 02 03 04 05 06 07
3、sed實現
root@PC1:/home/test2# ls a.txt root@PC1:/home/test2# cat a.txt 01 02 03 04 05 06 07 08 09 10 root@PC1:/home/test2# tac a.txt 10 09 08 07 06 05 04 03 02 01 root@PC1:/home/test2# tac a.txt | sed '1,3d' | tac ## 刪除后三行 01 02 03 04 05 06 07