A Guide to the Ubuntu Terminal

Cover Photo Ubuntu Terminal 01

In this tutorial we will be learning how to use the ubuntu terminal efficiently. You’ll find a lot of interesting things in this tutorial that might boost your productivity while using Ubuntu.

Alright let’s get right into it! First to run the terminal in ubuntu we can press Ctrl+Alt+T or you can press the Super(windows) key and type in ‘terminal’ and press enter. And a nice looking terminal would be right in front of you.

Ubuntu Terminal Basics

The Ubuntu Terminal
The Ubuntu Terminal

This is what the default terminal window on Ubuntu looks like.

  • Here, the first thing we see “dheeraj@linuxfordevices: ~$” right before the text prompt. First thing “dheeraj” here is the logged-in user who is running the commands. On your machine, it will be your username.
  • Then “linuxfordevices” is the machine name. After that, we see the ‘~’ symbol. This part will show us the present working directory, the directory we are currently in. In this case, we are in the home directory (/home/user) which is also represented by the ‘~‘ symbol.

To check the current directory, you can also type in the command ‘pwd‘ and press enter.

We can jump across different directory using the cd command. Just type in “cd directory-name” and press enter.

Pwd Cd And Ls Command
Pwd Cd And Ls Command

To see all the files of the present directory you can run the ‘ls’ command.

The Help Option and the man page

Sometimes it could be tricky to go around a command in Linux. The help option comes in very handy at those times. Simply run a command by after adding “-h” or “–help” after it and you will see a brief guide on how to use the command.

Here, I am looking for help on the cd command.

The Help Option
The Help Option

Also, if you’re looking for a more detailed reference you can use the man page. To refer to the man page of a command, you can type ‘man command-name’ and press enter.

Since, man is also a separate command, you can refer man page of man by running “man man”. 😀

Man Page
Man Page

The Clear Command

If you have a lot of clutter on the terminal screen you can run the clear command to clean everything.

Clear Command In Ubuntu
Clear Command In Ubuntu

The History Command

The up and down key on the keyboard will help you navigate through the previous commands. For example, pressing the up key once will bring up the last command that was executed, and pressing the up key again will bring up the command executed before that.

Up Down Key In Terminal
Up, Down Key In Terminal

You can also run the history command and it will show all the previously run command in the session.

The History Command
The History Command

Auto-Completion

The tab key on the keyboard helps to autocomplete a command. For the demonstration here, I will be opening a text file kept on my desktop.

First, I will navigate to the desktop using the cd command. The command is simply ‘cd Desktop’ but I don’t have to write the full command and just press tab after simply typing ‘cd De’ and it will autocomplete for me.

Tab Completion
Tab Completion

You can also press the tab key twice and it will list out all the possible completion options for what you’ve typed. For example, I am running the ‘cat’ command here, pressing tab twice will list out all the options here.

Double Tab Completion
Double Tab Completion

The !! option

The !! (pronounced ‘bang bang’) option simply copies the last command. One of the most common use of this is when you have to run the previous command with sudo privileges.

Sudo
Sudo !!

Running Multiple Commands

There are various methods to run multiple command at once in the terminal.

Running Multiple Commands
Running Multiple Commands
command1 ; command2 ; command3

The semicolon(;) operator will execute all the commands in succession, regardless of whether if any previous command fails or succeeds.

command1 && command2 && command3

The logical AND operator(&&) will only execute the second command once first is ran successfully and similarly will run the third command if second was successful and so on.

command1 || command2 || command3

The logical OR operator (||) will only execute the first successful command. It will execute command 2 only if command1 fails. And command3 if command2 fails.

The Alias Command

The alias command helps you create aliases for other commands. You can abbreviate longer commands with alias. For example:

alias sai="sudo apt install"
alias clr="clear"

You can use these aliases as good as the original commands. However, these aliases will be gone once you close the terminal session.

You can make the permanent aliases by editing the “.bashrc” file. It will not take very long, we will first open the file using nano text editor with the following command:

nano ~/.bashrc
Editing Bashrc File
Editing Bashrc File

Now you can add all the alias command at the bottom of the file.

#
#
alias sai="sudo apt install"
alias clr="clear"

And now save and exit the nano editor. After restarting the terminal, you will be able to use the set aliases.

Ubuntu Terminal Keyboard Shortcuts

Here are a few keyboard shortcuts that might come in handy:

  • Ctrl + Alt+ T: Open up a new terminal
  • Ctrl + Shift + T: New Terminal tab
  • Ctrl + C: Kill current running command/process
  • Ctrl + L: Clear Console
  • Ctrl + Shift + C: Copy selected text
  • Ctrl + Shift + V: Paste the copied text to the terminal
  • Ctrl + A: Go to the beginning of the line
  • Ctrl + E: Go to the end of the line

Conclusion

I hope after reading this tutorial, you will be be using the ubuntu terminal more efficiently. Have a great day ahead! Cheers!