10+ Basic Cat Command Examples in Linux [2023]

10+ Basic Cat Command Examples in Linux [2023]

10+ Basic Cat Command Examples in Linux [2023]

cat command is used for various file management tasks like creating single or multiple files, viewing the content of a file, concatenating files, and redirecting output in terminal or files.

Let’s have a look at the Cat command syntax and the examples.

10+ Basic Cat Command Examples in Linux [2023]

Linux is all about playing with different commands for the job execution cat is most commonly used to display the contents of text files

Cat Command Syntax

cat [OPTIONS] [FILE_NAMES]

1. Displaying The  Contents of File with Cat command

One of the most common uses of the cat command is to display the content of the file. Run the following cat command to display the contents of /etc/issue file.

# cat /etc/issue

2.  Redirect The Contents of the file using cat command

Run the following command to redirect the content of the file from one file to another.

cat file1.txt > file2.txt

3. View Contents of Multiple Files in terminal

In below example, it will display the contents of the test and test1 file in the terminal.

# cat test test1

Hello everybody
Hi world,

4. Create a File with Cat Command

Run the following command to create a file called newfilecreated with the below command.

# cat >newfilecreated

It will ask input from the user, after providing input press CTRL+D (hold down Ctrl key and type ‘d‘) to exit. Now you can see the content in the “newfilecreated” with

# cat newfilecreated

Run the following command with more and less parameters when you have a file with large content.

# cat largefile.txt | more
# cat largefile.txt | less

Run the following cat command with the -n option

# cat -n file.txt

1  hi
2  my name is 
3  Akbar
4  Anthony

5. Display Multiple Files at Once

Run the following cat command to display the content of the multiple files at once.

# cat testfile; cat testfile1; cat testfile2

This is a testfile
This is the testfile1 file.
This is testfile2 file.

6. Redirecting Multiple Files Contain in a Single File

Run the following cat command to redirect multiple files in a newly created file called testfile3

# cat test testfile1 testfile2 > testfile3

Summary: This is the example of the cat command in Linux and its usage with the examples. Let us know if you have any queries about this article.

READ More Relevant Stuff:  Ubuntu-Based Feren OS 2022.03, Independent Distro 4MLinux 39.0, Debian GNU/Linux 11.3 “Bullseye” Released

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply

    Your email address will not be published. Required fields are marked *