题解 | #打印文件的最后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 云南

相关推荐

点赞 评论 收藏
分享
10-15 20:01
已编辑
上海大学 Java
钉钉什么垃圾公司,约面鸽人
光年在眼前:不是坏事,感觉钉钉挺逆天的,二面结束还给我留作业,让我使用钉钉和看最新的发布会,然后说感受,我是应该不会去,三面直接拒绝不面了
点赞 评论 收藏
分享
评论
19
5
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务