linux打印文件第二到五行,head(输出一个文件或多个文件的第一部分)_语法_示例_Unix&Linux命令_uc电脑园官网...

本文介绍如何利用Linux命令行工具head来查看文件的前几行内容。涵盖了从显示文件的前10行到指定行数、字节数的各种用法,并支持同时处理多个文件及标准输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

head myfile.txt

Display the first ten lines of myfile.txt.

head -15 myfile.txt

Display the first fifteen lines of myfile.txt.

head myfile.txt myfile2.txt

Display the first ten lines of both myfile.txt and myfile2.txt, with a header before each that indicates the file name.

head -n 5 myfile.txt myfile2.txt

Displays only the first 5 lines of both files.

head -c 20 myfile.txt

Will output only the first twenty bytes (characters) of myfile.txt. Newlines count as a single character, so if head prints out a newline, it will count it as a byte.

head -n 5K myfile.txt

Displays the first 5,000 lines of myfile.txt.

head -c 6M myfile.txt

Displays the first six megabytes.

head -

If a dash is specified for the file name, head reads from standard input rather than a regular file.

head myfile.txt myfile2.txt -

Display the first ten lines of myfile.txt, myfile2.txt, and standard input.

head -n 4 *.txt

Display the first four lines of every file in the working directory whose file name ends in the extension .txt.

head -n 4 -q *.txt

Same as the previous command, but uses quiet (-q) output, which will not print a header before the lines of each file.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值