当前位置:首页 > 行业动态 > 正文

Linux下tail命令用法

tail命令在Linux中用于输出文件的末尾部分内容,它可以显示文件的最后几行,或者实时监控文件的变化,以下是一些常用的tail命令用法:

1、显示文件的最后N行

Bash
tail n N 文件名 

显示文件test.txt的最后10行:

Bash
tail n 10 test.txt 

2、实时监控文件的变化

Linux下tail命令用法

Bash
tail f 文件名 

实时监控文件test.txt的变化:

Bash
tail f test.txt 

3、显示文件的最后N行,并忽略空行

Bash
tail n N q 文件名 

显示文件test.txt的最后10行,并忽略空行:

Bash
tail n 10 q test.txt 

4、显示文件的最后N行,并显示行号

Linux下tail命令用法

Bash
tail n N n 文件名 

显示文件test.txt的最后10行,并显示行号:

Bash
tail n 10 n test.txt 

5、显示文件的最后N行,并显示时间戳

Bash
tail n N t 文件名 

显示文件test.txt的最后10行,并显示时间戳:

Bash
tail n 10 t test.txt 

6、显示文件的最后N行,并显示时间戳和行号

Linux下tail命令用法

Bash
tail n N T 文件名 

显示文件test.txt的最后10行,并显示时间戳和行号:

Bash
tail n 10 T test.txt