Overview
This guide covers everything from the basics to practical applications of the cat command, one of the most widely used commands in Linux and Ubuntu terminals. Beyond simply displaying file contents, we introduce features such as displaying line numbers, visualizing whitespace/non-printing characters, file concatenation, and creating files using EOF (Heredoc) along with practical examples.
1. Basic Usage of cat Command and Instantly Viewing Text File Contents
Run the command echo "Hello Ubuntu 24.04 LTS World!" > sample.txt to create a sample text file to be used for practicing the cat command.

The cat command outputs the entire contents of a specified text file to the terminal screen.
Running the command cat sample.txt immediately displays the contents written in the file on the screen.
⚙️ [Key Options]
-n : Displays line numbers for all output lines.-b : Displays line numbers only for non-blank lines.-s : Squeezes multiple consecutive blank lines into a single blank line.-E : Displays a $ character at the end of each line to visualize line breaks.-T : Converts tab (TAB) characters to ^I for display.-A : Visualizes all elements inside the file, including tabs, line breaks, and control characters.

2. How to Use Line Number Display (-n) and Special Character Visualization (-A) Options
Run the command echo -e "First Line\nSecond Line\n\nFourth Line\tTabbed" > options_demo.txt to prepare a sample file for practicing cat command options.

Running the command cat -n options_demo.txt outputs all lines in the file with line numbers attached, including blank lines.
This allows you to quickly identify exact line positions at a glance when navigating code or configuration files.

Running the command cat -A options_demo.txt visualizes all invisible control characters, such as tabs and line breaks.
A $ character is appended to the end of each line, and tab (TAB) locations are displayed as ^I, enabling you to clearly identify special characters or formatting errors within the file.

3. Combining Multiple Text Files (Concatenate) and Saving to a New File
Run the command echo "[Server Config]" > part1.txt to create part1.txt, the first configuration file to be used for practicing file concatenation with the cat command.
![echo “[Server Config]” > part1.txt](/ubuntu/20260829_071443_3_cat_cat/captures/s03_c01_echo___Server_Config_____part1_txt.png)
Next, run the command echo "Port=8080" > part2.txt to create part2.txt, the second configuration file to be merged.

Run the command cat part1.txt part2.txt > combined_config.txt to concatenate the contents of the two files in sequence.
Using the redirection symbol (>) allows the merged result to be directly saved as a new file named combined_config.txt instead of displaying it on the terminal screen.

Run the command cat combined_config.txt to check the full contents of the merged file.
You can see that [Server Config] from part1.txt and Port=8080 from part2.txt have been sequentially combined and saved into the file.

4. Creating Multi-line Files in the Terminal Without an Editor (Heredoc / EOF)
Run the command cat << 'EOF' > heredoc_demo.txt to create a multi-line text file named heredoc_demo.txt directly in the terminal without opening a separate text editor.
Using the Heredoc (<< 'EOF') syntax together with the redirection symbol (>), you can immediately save the typed text into a file until the EOF delimiter is entered.

Run the command cat heredoc_demo.txt to verify the complete contents of the file created on the fly with Heredoc.
You can see that the entered lines Line 1: Server Setup and Line 2: Firewall Config are properly saved in the file and printed on the screen.

5. Limitations of cat with Large Files and Combining Alternative Commands (head, tail) via Pipes
Run the command seq 1 100 > large_log.txt to generate a sample log file for practicing large file navigation.

Running the command head -n 5 large_log.txt outputs only the top 5 lines starting from the first line of the specified file to the terminal screen.
Unlike the cat command, it does not output the entire content of a large file, making it useful for quickly inspecting the file header structure or starting section.

Running the command tail -n 5 large_log.txt selectively outputs only the bottom 5 lines from the end of the specified file.
Without needing to open the entire file, you can efficiently check the latest updated logs or ending records.

Run the command cat large_log.txt | grep -E "(10|50|100)" to filter and output only the lines containing the specified patterns 10, 50, and 100 from the file content.
By piping (|) the terminal output retrieved by cat into the grep command, you can quickly search for lines containing specific keywords within large files.

So far, we have taken a look at useful tips for using the Linux cat command, from file viewing to merging and file creation.
We hope you refer to the various techniques shared above to create a more efficient Linux terminal environment.