Skip to main content

Linux Command Line Tutorial For Beginners - cat command

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

Comments

Popular posts from this blog

Linux Command Line Tutorial For Beginners - Introduction

Hi Friends, Welcome to Blog , Welcome to Linux . Now first question you may ask yourself why we should learn command line, even if we have GUI ? So, Simple answer is that GUI ( Graphical User Interface ) is helpful in many task but not useful in all task, and when you learn command, you will observe that you are able to do your day to day task or any task related to programming much faster that you can do with GUI . By using command you can able to see what happening in a background when you given a something task. Before dive into the world of Linux you should know two terms i.e., Shell and Terminal. Now what is Shell? Shell is a simply a program that takes inputs from the keyboard and gives that to the operating system to perform task.It is also called as CLI ( Command Line Interface ), Now the second term is Terminal, terminal is tool which is used to pass a shell command, this is a program that open up a window and lets interacts with shell. There are different operating...

Linux Command Line Tutorial For Beginners - ls command

ls is a Linux shell command that lists directory contents which may be files or directories. First of all lets open Terminal, Alt+Ctrl+T ls command uses following syntax:          ls [option] [file or directory name] if we give simple ls command it will show us all directories and files present in home directory, as when we open terminal by default we are in home directory. Now if we want to see what is in Downloads directory then we simply give command as:                          ls Downloads Note one thing i.e., command line is case sensitive so we should write name of directory or file as it is. In same way you can able to see contents of any directory. If we want to see content of root directory then we will write command as: As we know / is called as root directory.      ...