题解 | #打印文件的最后5行#

打印文件的最后5行

http://www.nowcoder.com/practice/ff6f36d357d24ce5a0eb817a0ef85ee2

该题考察的是 shell 的『tail』 指令; 对应还有一个『head』指令;

一、tail 【主要从文件的尾部操作查询文件】

1、tail -f nowcoder.txt : 实时输出文件的最新更新内容;

2、tail -n 5 nowcoder.txt [或者:tail -5 nowcoder.txt] : 输出文件的最后5行;

3、tail -n +5 nowcoder.txt : 输出从第5行开始到文件结尾的内容;

4、tail -n -5 nowcoder.txt : 输出从倒数 第五行开始到文件结尾的内容;

5、tail nowcoder.txt : 不加任何参数,默认输出10行;

6、tail -c 5 nowcoder.txt : 表示输出文件最后5个字节;

二、head 【主要从文件的头部操作查询文件】

1、head -n 5 nowcoder.txt 【或者:head -5 nowcoder.txt 】 : 表示输出文件开头前五行; 2、head -c 5 nowcoder.txt : 表示输出文件开头的5个字节;

全部评论
tail –n -5 nowcoder.txt;
点赞 回复 分享
发布于 2022-11-03 21:33 云南

相关推荐

17 5 评论
分享
牛客网
牛客企业服务