Command Line Interface(CLI) is a user interface that is used to operate software and operating systems which allows the user to respond to visual prompts by typing commands into the interface and receives the reply in the same way. It is somewhat different from Graphical User Interface(GUI) which is used in the latest operating system. But today’s UNIX systems offers both command line interface and graphical user interface.
CLI was introduced with the teletypewriter machine. This system was based on batched processing. The modern computers support CLI, batch processing and Graphical User Interface(GUI) in one interface.
Executing commands in CLI:
CLI is a text based interface and the user performs tasks by entering the commands. It’s working mechanism is easy but it’s not user-friendly. The user enters commands and press “Enter” to execute a command. Then CLI receives the command and processes it accordingly and shows the result on the same screen by using command line interpreter. Some programming languages such as Forth, Python, and BASIC offers CLI to enter many commands and process it.
How to print last 20 lines of a file to CLI?
The last 20 lines of a file can be printed to Command Line Interface by using tail command.
The ‘tail’ command is used to view the end of a text file and prints the text of the file in the command line interface. It is useful in reading the files where the relevant content will be appended to the end of a file such as logs. It also helps in reading the error messages.
It uses the following arguments to display the files in the specific type. The options are listed below.
$ tail -n – Displays the specified number of lines in a file.
$ tail -c – Displays the specified number of bytes from the last.
$ tail -f – Continuously watch for any additions in the file.
$ tail -f–pid=PID – Continuously displays any additions until process with PID terminates.
$ tail -f-s<sec> – Continuously displays any additions at intervals of <sec> seconds.
Command used to print last 20 lines of a file:
The command tail -n <filename> is used to print the last line of a file.
The command tail -20<filename> is used to print the last 20 lines of a file.
For example, tail -20 filename.txt prints the last 20 lines of the file filename.txt