How to Display content of a file in Terminal Screen?


If you want to see content of a file in Terminal make use of the cat command,

Syntax: cat [file...]

Example:
$ cat myfile.txt
This is my text file.
This file has multiple lines.

You can also use this command to concatenate and display content of multiple files as well,

Example:
$ cat myfile.txt myfile1.txt 
This is my text file.
This file has multiple lines.
This is file 2

✌️Note that when you cat multiple files at a time the content are displayed as read-only and no files are written!

If you file is not at the current location, you can also provide absolute path as well,

$ cat /Users/c2c/Desktop/myfile.txt
This is my text file.
This file has multiple lines.


Display content of a huge file with more and less option

Display content of a file in terminal example

If you want to display the content of a file that has many lines, the whole content of the file is printed on the screen and many not be able to see all the data as the scroll will be enabled and you will end up at the bottom of the screen, in such case you can make you of more or less command,

Example:
$ cat myfile.txt | more
This is my text file.
This file has multiple lines.
Line 1
Line 2
Line 3
Line 4
Line 5
Line 6
Line 7
Line 8
Line 9
:

You can press spacebar to get more data displayed in screen (next batch) or q to quit and come back to the prompt.

Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.