cat command | How to view the content of a File in Linux

Hello, everyone In this Article we are going to learn how to view the content of the file in Linux in a very simple and easy step-by-step approach.

cat

cat command

The cat command has two purposes 1st it is use to create a file and add the content inside the file

2nd we can also read the content of any file using the cat command.

The cat command also concatenates the files to standard output

Before Jumping on the command we should know the syntax of the mkdir command

cat [Option]… FileName…

1 ) How to create a file using cat command

Using > symbol we can create any file using the cat command after writing this command it will ask to take input from the user to add the content inside the File1.txt file press enter then ( Cntrl + d ) to save the file with its content

$ cat > File1.txt
Screenshot 2 31

2) How to View the content Of a file

To read the content inside of the file that we have made then we can use the cat command

$ cat File1.txt
Screenshot 1 34

3) How to View the content of a file in a line number format

The ( -n  )option is used to show the content with the line number attached.

$ cat -n File1.txt
Screenshot 3 32

4 ) How to append the content in a File

To add more content inside the file ie. we want to append inside the file then we can use( >>  ) option in the cat command

$ cat >> File1.txt
Screenshot 4 31

Now when we see the content using cat command we get our new content appended to our file

Screenshot 5 31

5 ) How to override the content in a File

If we use ( > ) option with the cat command then the content will be overridden with the current content.

$ cat > File1.txt

Now when we see the content using cat command we get our new content is override in our file

Screenshot 6 30

Now when we see the content using cat command we get our new content Override to our file.

Screenshot 7 25

6 ) How to View the content of the file with the line number with nl command

If we only want to read any file then we can use nl command. the nl command is only used to read the file. with the line numbers.

$ nl File1.txt
Screenshot 3 33

7) How to View the Content of a file in reverse order

If we want to read the file but in reverse order
Then we can use the tac command. Please note that we cannot use the (-n) option with the tac command.

$ tac File1.txt
Screenshot 9 25

8 ) How to check version Of the cat command 

To check what is the version of the cat command then we can execute the below command

$ cat --version
Screenshot 11 24

9) How to View the Most useful Options in the cat command 

If we want to know the most useful options with the cat command then we can execute the below command.

$ cat --help
Screenshot 12 20

Conclusion

If you want to learn Linux in the most simple language then please click on this link

If you want to see the man page of cat command online then click on this link

This is the complete knowledge of how we can view the content of the file in the Linux kernel using the cat command if you have any doubts please feel free to comment below. Please don’t forget to join our email subscription to get the latest updates on DevOps Articles.

Leave a Comment