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

</>
Copy
cat path/to/file

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.

Linux - Display contents of a file - cat command

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.

Linux - Display contents of a file - cat and less commands

The contents of the file or displayed as shown in the following screenshot.

Linux - Display contents of a file

Once you’re done reading the contents of the file, enter ctrl + Z from keyboard to come out of the file viewer.

Linux - Display contents of a file

We are back to the prompt in Terminal.

Conclusion

In this Linux Tutorial, we learned how to view the contents of a file, using cat and less commands.