Linux cat command
The cat
command in Linux is a versatile utility used to concatenate and display the content of files. It can also be used to create new files, copy the content of existing files, and concatenate multiple files into a single output. Cat
stands for “concatenate” and is a fundamental tool in the Linux command-line environment. It is commonly used in shell scripts and terminal commands to manipulate and view text files efficiently. The cat
command accepts various options and arguments to modify its behavior, providing flexibility and control to users.
cat Syntax:
Options:
Option | Description |
---|---|
-b | Number non-blank output lines |
-n | Number all output lines |
-s | Squeeze multiple adjacent blank lines into one |
-E | Display a $ at the end of each line |
-T | Display TAB characters as ^I |
-v | Display non-printing characters as ^ notation |
Parameters:
Parameter | Description |
---|---|
[file] | Specify the file to be displayed, if not provided, |
cat reads from the standard input (stdin) |
cat Usage:
Display File Contents
This command displays the contents of the file.txt on the terminal.
Concatenate Multiple Files
Concatenates and displays the contents of both file1.txt and file2.txt on the terminal.
Create a New File
Creates a new file named newfile.txt and allows you to input text. Press Ctrl+D to save and exit.
Display Line Numbers
Displays the contents of file.txt with line numbers shown at the beginning of each line.
How can I display the contents of a file using cat in Linux?
To display the contents of a file using the cat command in Linux, run:
How do I combine multiple files and display the output using cat in Linux?
To combine multiple files and display the output using the cat command in Linux, use:
How can I create a new file by combining existing files with cat in Linux?
To create a new file by combining existing files using the cat command in Linux, you can do:
How do I number all output lines while displaying file contents with cat in Linux?
To number all output lines while displaying file contents using cat in Linux, execute:
How can I display the contents of a file in reverse order with cat in Linux?
To display the contents of a file in reverse order using the cat command in Linux, use:
How do I append the content of a file to another file using cat in Linux?
To append the content of one file to another file with the cat command in Linux, run:
Applications of the cat Command
- Viewing the contents of a file
- Concatenating multiple files and displaying the output
- Creating a new file by combining existing files
- Appending the contents of one or more files to another file
- Displaying line numbers while viewing a file
- Creating a new file and entering text directly from the command line