Home Terminal tips and tricks

Terminal tips and tricks


When it comes to linux terminals I have been fortunate enough to have come across many tips and tricks from many of my mentors, colleagues and as well as the internet(Stack Overflow obviously).

The first one is my personal favourite and is one that everybody badly needs, have you ever run a command and then get the most common error that you do not have permission or you need to be root only to realise you haven’t used sudo and then you end up either retyping the command like sudo <your-command> or you press the up arrow and then keyboard shortcut home button and then type sudo to end up with sudo <your-command> What if you could just use sudo bang bang instead, a cooler and much efficient way to re-run immediate previous command but with modifications, in our context adding the sudo to the beginning.

Ex: When you run the below

ls /root


ls: cannot open directory '/root':

So, run the below command where !! will append the previous run command.

sudo !!


sudo ls /root
[sudo] password for ubuntu:

Reverse lookup on history (commands that were run previously)

Ctrl+r and type parts of previously used command. For example, to get a previously run ssh command

Key in Ctrl=r and start typing

(reverse-i-search)`ssh': ssh -i ~/.ssh/id_rsa root@

Exit a session using exit command or shortcut Ctrl+d


or use Ctrl-d

This post is licensed under CC BY 4.0 by the author.