Line 1: Hello, world!
Line 2: This is a sample file.
Line 3: It contains multiple lines.
Line 4: Each line represents a different content.
Line 5: The last line of the file.
使用不同的选项来查看文件的内容:
2.2.1 默认显示前10行
$ head file.txt
输出:
Line 1: Hello, world!
Line 2: This is a sample file.
Line 3: It contains multiple lines.
Line 4: Each line represents a different content.
Line 5: The last line of the file.
由于文件只有5行,所以只显示了前5行。
2.2.2 显示前3行
$ head -n 3 file.txt
输出:
Line 1: Hello, world!
Line 2: This is a sample file.
Line 3: It contains multiple lines.
使用-n选项指定显示前3行。
2.2.3 显示前10个字节
$ head -c 10 file.txt
输出:
Line 1: He
使用-c选项指定显示前10个字节。
2.2.4 不显示文件名
$ head -q file.txt
输出:
Line 1: Hello, world!
Line 2: This is a sample file.
Line 3: It contains multiple lines.
Line 4: Each line represents a different content.
Line 5: The last line of the file.
使用-q选项不在输出中显示文件名。
2.2.5 显示文件名
$ head -v file.txt
输出:
==> file.txt <==
Line 1: Hello, world!
Line 2: This is a sample file.
Line 3: It contains multiple lines.
Line 4: Each line represents a different content.
Line 5: The last line of the file.