Improving your productivity on Linux Terminal


preview imageProgramming
by Anurag Srivastava,Nov 29, 2020, 5:16:40 PM | 4 minutes |
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.

Example:
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:

!tail

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.

Example:
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

preview thumbnail
Introduction to Kibana

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

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava

preview thumbnail
Introduction to Elasticsearch Aggregations

Aug 14, 2018, 4:47:56 PM | Anurag Srivastava

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

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

preview thumbnail
Basics of Data Search in Elasticsearch

Aug 4, 2018, 7:02:21 AM | Anurag Srivastava

Top Blogs

preview thumbnail
Wildcard and Boolean Search in Elasticsearch

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

preview thumbnail
Elasticsearch REST APIs

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

preview thumbnail
preview thumbnail
Create a Chess board in PHP

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

preview thumbnail
Bucket Aggregation in Elasticsearch

Aug 29, 2018, 7:15:06 PM | Anurag Srivastava

preview thumbnail
Metrics Aggregations in Elasticsearch

Aug 18, 2018, 6:02:20 PM | Anurag Srivastava