Display contents of a file in Linux
To Display contents of a file in Linux, we can use cat command.
The cat command to display the contents of a file is
For example, from the following screenshot, there is a file named info.txt in the current working directory. We have used cat command to display the contents of the file.
Sometimes, the contents of the file would be greater than that can be accommodated on the terminal screen. In that case, we can use less command, piped with the cat command, to enter the file where we can navigate the file contents using up and down arrows.
For example, in the following screenshot, we have piped the less command with cat command to display the contents of file.
The contents of the file or displayed as shown in the following screenshot.
Once you’re done reading the contents of the file, enter ctrl + Z from keyboard to come out of the file viewer.
We are back to the prompt in Terminal.
In this Linux Tutorial, we learned how to view the contents of a file, using cat and less commands.