Sobes.tech
Middle+

How to view the contents of a text file in Linux?

sobes.tech AI

Answer from AI

In Linux, several commands can be used to view the contents of a text file:

  • cat filename — displays the entire file.
  • less filename — paginated viewing with scrolling capability.
  • more filename — similar to less, but with simpler functionality.
  • head filename — shows the first 10 lines of the file.
  • tail filename — shows the last 10 lines, useful for logs.

For example, to view the first 20 lines of a file:

head -n 20 filename.txt

Or to view a file with scrolling:

less filename.txt
How to view the contents of a text file in Linux… - sobes.tech