Linux cat Command [12 Basic Examples]

Introduction to Linux cat Command

cat command in Linux is basically a short name of “concatenate”, and is frequently used to create single or multiple files, view its content, concatenate them, and display their output on screen. Also, the output can be saved in a specified file as well. So, this article brings you 12 basic examples of Linux cat command to describe how cat command can be used in Linux terminal.

Also Read:   How To Use ‘access’ command in Linux

Syntax of cat command in Linux

cat [OPTION] [FILE]…

Options available to use cat command

To view all available options to use cat command in Linux, run “cat –help” in terminal.

Linux cat command

Basic examples of Linux cat command:

1: Viewing contents of a file named servonode.txt

cat servonode.txt

2: Viewing multiple files, say servo.txt, and node.txt

cat servo.txt node.txt

3: Displaying contents with line number

cat -n servonode.txt

4: Create a file with cat command

cat >servnode.txt

5: Copying content of one file to another (From servo.txt to node.txt)

cat servo.txt > node.txt

6: Suppressing empty lines in servonode.txt

cat -s servonode.txt

7: Append content of servo.txt to the end of node.txt

cat servo.txt >> node.txt

8: To display content of a file in reverse order (Using tac command)

tac file_name

9: Highlight the end of line in servo.txt

cat -E “servo.txt”

10: Open dashed files like -servo.txt

cat - - “-servo.txt”

11: Displaying file content with “Show More” (For files with a lot of content)

cat “file_name” | more

12: Merge contents of servo.txt with node.txt and create a new file merged.txt

cat “servo.txt” “node.txt” > “merged.txt’

Nishant

Nishant Verma is a senior web developer who love to share his knowledge about Linux, SysAdmin, and more other web handlers. Currently, he loves to write as content contributor for ServoNode.