Thursday, 30 November 2023   |

How to Print Last 10 Lines of Files in Linux


To print the last 10 lines of a file in Linux, you can use the `tail` command with the `-n` option. Here's how you can do it:

```
tail -n 10 filename
```

Replace `filename` with the actual name of the file you want to display the last 10 lines of. The `tail` command outputs the last part of a file by default, and the `-n` option specifies the number of lines to display (in this case, 10).

If you want to continuously monitor a file and display the last 10 lines as new lines are added to it, you can use the `-f` option along with `tail`. This is useful, for example, when monitoring log files:

```
tail -f -n 10 filename
```

This command will display the last 10 lines of the file and then continuously update the output as new lines are appended to the file. You can terminate the continuous output by pressing Ctrl+C.

Note that the `tail` command assumes the file is a text file. If you try to use it on a binary file, the output may not be meaningful.


Date: 20 June 2023    Comments: 0


Comments - 0

There are no comments yet

Leave A Comment