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.

Copyright Β© Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap