In this post we will learn how to use cat command in Linux.
cat is one of the most frequently used command in Linux and it has three functions with respect to text files :
1) Displaying text file.
2) Combining copies of text files.
3) Creating new text files.
So, lets see how we can use cat command.....
First of all open Terminal, Alt+Ctrl+T
Syntax for cat command is :
cat [option] [file name]
Now lets move towards our command, give command as only :
cat
You will find that nothing is happened, but our cursor is blinking like this:
Now type anything for example if we type Hello then press Enter it will again print the same word i.e., called as Echo.
For exiting from cat command you simply press Ctrl+D, Which means end of program.
cat command is not only for echoing something but along with this it is used to do many functionality.
Now, if we want to display content of file on Terminal, then we will give command as:
cat [file name]
In above terminal example file text.txt contains content will be displayed on terminal.
Now, if we want to display content of two or more files using single command then we will give command as:
cat [file name 1] [file name 2]
There are some options available with cat command for example if we we want to display line number with content of file the we will give command as:
cat -b [file name]
Note one thing -b will display number only to the non-blank line as shown in above picture.
Now, if we want to give line number to all the lines even if they are blank the we will give command as:
cat -n [file name]
Now, if we want to know where does our line ends then we will give command as:
cat -E [file name]
Here you can see that at the end of each line $ (dollar) sign is added.
For more options try command:
man cd
Now, Here is one question for you,
You tell we what will be the output ?
when we will give command as:
cat -s [file name]
Try this command on your terminal and answer my question.
Correct answer will be show in next post.
Thanks for reading my blog.
Next time I will come will new command related to cat I/O redirection.
If you have any query, suggestion, or feedback let me know through comment section or you may contact with me.
Contact Details:
Phone: +91-8208826234
E-mail: shivampawar1038@gmail.com
cat is one of the most frequently used command in Linux and it has three functions with respect to text files :
1) Displaying text file.
2) Combining copies of text files.
3) Creating new text files.
So, lets see how we can use cat command.....
First of all open Terminal, Alt+Ctrl+T
Syntax for cat command is :
cat [option] [file name]
Now lets move towards our command, give command as only :
cat
You will find that nothing is happened, but our cursor is blinking like this:
Now type anything for example if we type Hello then press Enter it will again print the same word i.e., called as Echo.
For exiting from cat command you simply press Ctrl+D, Which means end of program.
cat command is not only for echoing something but along with this it is used to do many functionality.
Now, if we want to display content of file on Terminal, then we will give command as:
cat [file name]
In above terminal example file text.txt contains content will be displayed on terminal.
Now, if we want to display content of two or more files using single command then we will give command as:
cat [file name 1] [file name 2]
There are some options available with cat command for example if we we want to display line number with content of file the we will give command as:
cat -b [file name]
Note one thing -b will display number only to the non-blank line as shown in above picture.
Now, if we want to give line number to all the lines even if they are blank the we will give command as:
cat -n [file name]
Now, if we want to know where does our line ends then we will give command as:
cat -E [file name]
Here you can see that at the end of each line $ (dollar) sign is added.
For more options try command:
man cd
Now, Here is one question for you,
You tell we what will be the output ?
when we will give command as:
cat -s [file name]
Try this command on your terminal and answer my question.
Correct answer will be show in next post.
Thanks for reading my blog.
Next time I will come will new command related to cat I/O redirection.
If you have any query, suggestion, or feedback let me know through comment section or you may contact with me.
Contact Details:
Phone: +91-8208826234
E-mail: shivampawar1038@gmail.com
Comments
Post a Comment