Your Webhosting Questions
Answered by the Webhosting Experts

How to Use Cat Command on a Linux Server

Viewing Text File Content

The cat command allows you to read /view the contents of the text files without editing them. The easiest method of reading a file is to use the cat command followed by the filename, as shown in the example below:

cat logfile.txt

Screenshot showing the results of the cat logfile.txt command.

Moving Through Long Text Files

You can also append less to the cat command using a pipe (|), in order to check the file page by page.

See the below example with the marked colon, indicating that you can scroll up and down.

cat logfile.txt | less

Screenshot showing the results of the cat logfile.txt | less command.

Using cat Command to Redirect and Save

It is also possible to save the output contents of the cat command in a file. To do this, simply type cat followed by an output redirection operator.

cat /proc/cpuinfo > /root/cpu-information.txt

Screenshot showing the results of the cat /proc/cpuinfo > /root/cpu-information.txt command.

The cat command can also be used to read multiple files at the same time. If you want to combine and read multiple files, you can use the example below.

cat myfile1.txt myfile2.txt myfile3.txt

Screenshot showing the results of the cat myfile1.txt myfile2.txt myfile3.txt command.

You can also redirect the combined output to a new file as shown in the example below. 

cat myfile1.txt myfile2.txt myfile3.txt > newfile.txt

Screenshot showing the results of the cat myfile1.txt myfile2.txt myfile3.txt > newfile.txt command.

Need More Personalized Help?

If you have any further issues, questions, or would like some assistance checking on this or anything else, please reach out to us from your my.hivelocity.net account and provide your server credentials within the encrypted field for the best possible security and support.

If you are unable to reach your my.hivelocity.net account or if you are on the go, please reach out from your valid my.hivelocity.net account email to us here at: [email protected]. We are also available to you through our phone and live chat system 24/7/365.

Tags +
...