Blog Detail

Covid-19 Tracker Ask Question

preview image Programming
by Anurag Srivastava, Nov 29, 2020, 5:16:40 PM | 4 minutes |

Improving your productivity on Linux Terminal

For the last few years, I have been using a few commands on the Linux platform that have enhanced my productivity. Few of you might use these commands, but it is still traditionally done by many people. On Ubuntu, I use these commands. I think you can help improve your productivity by using the following commands:

"!" Command:

Using the above command we can run the previous instance of a command(along with the parameter), just by typing the command name. If we are executing the same command multiple times then instead of typing the complete command, we can just use {!COMMAND_NAME} and this will execute the complete command.

Assume you have a log file named "logfile" that you are checking regularly to see if there is any new entry. For that we need to execute the  following command every time: 

tail -200 logfile
Now instead of running the previous command, we can repeat the same command using the below command:


After executing the above command we will be getting the same response, please refer to the below screenshot:

In this way, we can use the "!" for any of the previous commands just by typing the name of the command along with the "!" sign. 

"!!" Command:

Using the above command we can execute the last executed command. The best use case is the situation where you need to append sudo before the command as you forgot to mention sudo before a command.

Let say you have executed the following command:

cp logfile /var/log/

Let say if you don't have the permission to copy the file at this location so you will get the "Permission denied" message. Now the option is to execute the same command again by appending the sudo keyword and the same can also be done just by using the following command:

sudo !!

The above command will execute "sudo cp logfile /var/log/" and this way we can save some time in scrolling up and appending the sudo keyword. Please refer to the below screenshot:

We can use the "!!" command whenever we want to refer to the previous command. So instead of doing the up arrow to find the previous command just type "!!" and hit enter to execute the previous command again.

"Ctrl+R" to fetch the matching command:

Using this command we can fetch the previously executed command by searching through the text. Just press "Ctrl+R" and type the text like if you want to search the previous SSH command then type SSH and this will fetch your SSH command that you may have executed recently. Once you type the text then press the "Ctrl+R" again to see multiple matched entries one by one.

This command is also very handy and saves a lot of time. If you have SCP, SSH, or any other long command that you want to execute again then it is good to just do a "Ctrl+R" search for the command, find the right one by again doing "Ctrl+R" and just hit enter. Please refer to the below screenshot:

The above screenshot is showing the step where after entering "Ctrl+R" we can type the text to match the commands.

Ctrl+L to clean the terminal screen:

You can easily clean the screen by pressing "Ctrl+L" using your keyboard. This shortcut will clear the screen, so instead of typing the "clear" command, you can just use this shortcut.

Pipe to join multiple commands:

Instead of executing multiple commands, we can use the pipe to join then. It is very useful as the command located on the left side of the pipe will work as input for the right side of the command. This saves a lot of time and also we can do a lot more using this pipe.

For example, the history command returns the history of all executed commands but if we want to know the history of the cp command then we can execute the following command:

history | grep cp
The above command will return all command having "cp", please refer to the below screenshot:

So these were some cool commands using that we can save some time and can improve productivity. There are many other commands also that can help us to improve productivity like alias and some other shortcuts. I will try to add them to this blog later.

If you have any further queries then please leave your comment. 

Comments (0)

Leave a comment

Related Blogs

Elastic Stack Interview Questions

Sep 12, 2020, 3:58:55 PM | Anurag Srivastava

Introduction to Kibana

Aug 1, 2020, 6:19:45 PM | Anurag Srivastava

Create a Chess board in PHP

Mar 9, 2020, 8:45:41 AM | Rocky Paul

Handle Excel file using Python (Part 2)

Dec 31, 2019, 1:33:53 PM | Anurag Srivastava

Handle Excel file using Python (Part 1)

Dec 30, 2019, 11:20:08 AM | Anurag Srivastava

Create a Pie Chart in Kibana

Dec 24, 2018, 5:25:28 PM | Anurag Srivastava

Top Blogs

Wildcard and Boolean Search in Elasticsearch

Aug 10, 2018, 7:14:40 PM | Anurag Srivastava

Elasticsearch Rest API

Jul 31, 2018, 6:16:42 PM | Anurag Srivastava