
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display the Last Part of a File in Linux
To display the last part of the file, we use the tail command in the Linux system.
The tail command is used to display the end of a text file or piped data in the Linux operating system. By default, it displays the last 10 lines of its input to the standard output. It is also complementary of the head command.
Syntax
The general syntax of the tail command is as follow −
tail [OPTION]... [FILE]...
Brief description of options available in the tail command.
Sr.No. | Option & Description |
---|---|
1 |
-c, --byte = [-]NUM Display the last NUM bytes of each file. Or -c +NUM to display starting with byte NUM of each file. |
2 |
-f, --follow [ = {name | descriptor}] Display appended data as the file grows. |
3 |
-F Same as --follow =name --retry |
4 |
-n, --lines [-]NUM Display the last NUM lines instead of the first 10. |
5 |
--max-unchanged-starts = N With --follow = name, reopen a FILE which has not |
6 |
--pid = PID With -f option, terminate after process ID, PID dies |
7 |
-q, --quiet, --silent Never prompt headers giving file names |
8 |
--retry Keep trying to open a file if it is not accessible |
9 |
-v, --verbose Always display headers giving file names |
10 |
-z, --zero-terminated Line delimiter is NULL, not newline |
11 |
--help Displays a help message and then exits. |
12 |
--version It gives info about the version and then exits. |
By default, the tail command prints the last ten lines without any option as shown in this example.
First, we will create a file containing more than ten lines using the cat command in the Linux system as shown below.
$ cat >text.txt First line... Second line...Third line... Fourth line... Fifth line... Sixth line... Seventh line... Eighth line... Ninth line... Tenth line... Eleventh line...
Then, we will use the tail command in the Linux system to display the last ten lines.
$ head text.txt Second line... Third line... Fourth line... Fifth line... Sixth line... Seventh line... Eighth line... Ninth line... Tenth line... Eleventh line...
To prints the last n lines, we use -n or --lines option with the head command as shown below.
Suppose we want to display the last four lines of the text.txt file then we have to execute the command as shown below.
$ head -n 4 text.txt
To check more information about the tail command, we use the --help option with the head command in the Linux operating system as shown below.
$ tail --help
To check version information of the tail command, we use the --version option with the tail command in the Linux operating system as shown below.
$ tail --version