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 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
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
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
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
Now when we see the content using cat command we get our new content appended to our file
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
Now when we see the content using cat command we get our new content Override to our file.
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
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
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
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
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.