Terminal often intimidates new users. However, you gradually start liking it once you get to know it. Well, that happens with most Linux users.
Even if you are using Ubuntu as a desktop system, you may sometimes have to enter the terminal. New users are often clueless about many things. Some knowledge of basic Linux commands always helps in such cases but this article is not about that.
This article focuses on explaining small, basic, and often ignored things about using the terminal. This should help new Ubuntu desktop users know the terminal and use it more efficiently.
The terminal you see is just one of the various terminal applications available. After all, the terminal is just a GUI tool that gives you access to a shell where you can run the commands.
Different terminal applications (properly called terminal emulators) look different and have slightly different functions and features (like different keyboard shortcuts, color combinations, fonts, etc).
This article specifically focuses on the default Ubuntu terminal, which implements the GNOME terminal.
1. Open the terminal with a keyboard shortcut
You can open the terminal in Ubuntu by looking for it in the system menu. However, my favorite way is to use the Ctrl+Alt+T keyboard shortcut in Ubuntu.
2. Terminal vs shell vs prompt vs command line
Before you see anything else, you should know the difference between different terminologies that are often (incorrectly) used interchangeably.
The terminal is a graphical application that runs a shell by default.
Shell is difficult to visualize separately from the terminal. The terminal runs a shell, usually Bash shell by default in Ubuntu. Like terminals, there are various shells as well. Bash is the most popular of them all and the default shell on most Linux distributions.
The commands you type are interpreted by the shell. Often people think that screen they see in the terminal is the shell. That’s fine for understanding.
Prompt is what you see before the space where you type the commands. There is no set standard for the prompt. In some old terminals, you would just have a blinking cursor to the place where you can type the commands. In the Ubuntu terminal, prompt gives you some information which you’ll see in detail in the later sections of this article.
The Command line is not something specific to Linux. Every operating system has a command line interface. Many programming languages have command line interfaces. It’s a term for the interface where you can run and execute commands.
This video by Luke Smith explains it in detail with examples. I won’t go into details anymore to keep things on track.
3. Understanding the prompt
You know it by now. What you see before the space where you type the command is called the prompt. It is configurable and looks different in different distributions, terminal applications and shells.
Ubuntu terminal has configured the prompt to show you a few things. You can get the following information at a glance:
- User name
- Hostname (name of the computer)
- Current working directory
A few more things you may wonder about.
The colon (:) in the prompt is a separator to distinguish between the hostname and the current location.
Tilde (~) means the home directory of the present user.
For regular users, the prompt ends with dollar ($) symbol. For the root user, it ends with pound or hash (#) symbol. And hence the joke that pound is stronger than dollar.
Did you notice that when I switched to the root user, the command prompt looked different without any colors? This is another reminder that prompt is not a standard and is configured explicitly. For regular users, Ubuntu has a different configuration of the prompt than the root.
Simple information like this helps indirectly. In a multi-user environment, you can easily figure out which user you are using and if it is a root user. The displayed location is also helpful.
4. Directory and files
The two terms you hear the most in Linux are directory and files.
You probably know what a file is but you may get confused with the term ‘directory’. The directory is nothing but a folder. It keeps files and folders inside it.
You can go inside the directories but you cannot enter files. You can read files of course.
You can use the term ‘folder’ for the directory, which should be fine. However, it is better to use ‘directory’ because this is what you’ll see referenced in various tutorials, documents etc. You’ll even find commands like rmdir, mkdir hinting that they deal with directories.
Additional note: Everything is a file in Linux. Even directory is a special kind of file that has the memory address of files and directories inside it. I have explained it in my article on hard links. You may refer to that if you want to know more on this topic.
5. Path: Absolute and relative
The directory structure in Linux resembles the root of a tree. Everything starts at root and spreads out from there.
If you have to access a file or directory, you need to tell how to reach its location by providing its ‘path’. This path is composed of directory names and separators (/). If a path starts with / (i.e., root), it is an absolute path otherwise it is a relative path.
The absolute path starts from the root and can be easily referenced from anywhere in the system. The relative path depends upon your current location in the directory structure.
If you are in the location /home/abhishek which has a directory named scripts containing a file my_script.sh and you want the path for this file, its absolute path will be:
Its relative path will be:
If you change the location, the file's absolute path remains the same. However, the relative path changes because it is relative to your current path.
6. . and ..
You may often come across . and .. notations while using the Linux terminal.
Single dot (.) means the current directory.
Double dots (..) mean the parent directory (one directory above the current location).
You’ll often use the double dot (..) in the relative path or for changing the directory. Single dot (.) is also used in relative path; more importantly, you can use it in the commands to specify the current locations.
7. Understand the command structure
A typical Linux command consists of a command name followed by options and arguments.
command [options] argument
Option, as the name suggests, are optional. When used, they might change the output based on their properties.
For example, the cat command is used for viewing files. You can add option -n, which will also display line numbers.
Options are not standardized. Usually, they are used as a single letter with single dash (-). They may also have two dashes (--) and a word.
Same options may have different meanings in a different command. If you use -n with head command, you specify the number of lines you want to see, not the lines with numbers.
In command documentation, if you see something between brackets (), it indicates that the contents of the bracket are optional.
Similarly, arguments are also not standardized. Some commands expect filenames as arguments and some may expect a directory name or regular expression.
8. Getting help
As you start using commands, you may remember some of the options of frequently used commands but it is simply impossible for you to remember all the options of any command.
Why? Because a single command may have more than ten or twenty options.
So, what do you do when you cannot recall all the options? You take help. And with help, I do not mean asking a question in It’s FOSS Linux forum. I ask to use the help option of the command.
Every standard Linux command has a quick help page that can be accessed with -h or –help or both.
It gives you a quick glimpse of the command syntax, common options with their meaning, and command examples in some cases.
If you need more help, you can refer to the manpage i.e. manual of a command:
It goes into all the details and could be overwhelming to read and understand. Alternatively, you can always search on the internet for ‘examples of xyz commands in Linux’.
9. Linux is case-sensitive
Linux is case-sensitive. Everything you type in the terminal is case-sensitive. If you do not take that into account, you’ll often run into bash: command not found or file not found errors.
In the home directory, you have all the folders' names starting with the upper case. If you have to switch to the Documents directory, keep the first letter as D and not d. Otherwise, the terminal will complain.
You can have two separate files named file.txt and File.txt because file and File are not the same for Linux.
10. Running shell scripts
You can run a shell script by specifying the shell:
Or you can execute the shell script like this:
The second one will only work when the file has the execute permission. More on Linux file permission here.
11. Use tab completion instead of typing it all
The Ubuntu terminal is pre-configured with tab completion. This means that if you start writing something in the terminal and then hit tab, it tries to automatically complete it or provide options if there is more than one possible match.
It works for both commands as well as arguments and filenames.
This saves a great time because you don’t have to write everything completely.
12. Ctrl+C and Ctrl+V is not for copy pasting in terminal
Ctrl+C, Ctrl+V might be the ‘universal’ keyboard shortcuts for copy paste but it doesn’t work in the Linux terminal.
Linux inherits a lot of stuff from UNIX and in UNIX, Ctrl+C was used for stopping a running process.
Since the Ctrl+C was already taken for stopping a command or process, it cannot be used for copy-paste any more.
13. You can surely copy paste in the terminal
Don’t worry. You can still copy paste in the terminal. Again, there is no fixed rule for the copy-paste keyboard shortcuts because it depends on the terminal application you are using or the configuration you have in place.
In the Ubuntu terminal, the default keyboard shortcut for copying is Ctrl+Shift+C; for pasting, it is Ctrl+Shift+V.
You can use Ctrl+C to copy text and commands from outside the terminal (like a web browser) and paste it using Ctrl+Shift+V. Similarly, you can highlight the text and use Ctrl+Shift+C to copy the text from the terminal and paste it to an editor or other applications using Ctrl+V.
14. Avoid using Ctrl+S in the terminal
Another common mistake beginners do is to use the ‘universal’ Ctrl+S keyboard shortcut for save. If you use Ctrl+S in the terminal, your terminal ‘freezes’.
This comes from legacy computing where there was no scope for scrolling back up. Hence, if there were many output lines, Ctrl+S was used to stop the screen so that text on the screen could be read.
You can unfreeze your terminal with Ctrl+Q. But again, avoid using Ctrl+S in the terminal.
15. Pay attention to $ and <> in command examples
If you are referring to some online tutorial or documentation, you’ll see some command examples with text inside <>. This indicates that you need to replace the content along with < and > with a suitable value.
For example, if you see a command like this:
grep -i <search_term> <file_name>
You should replace the <search_term> and <file_name> with their respective actual values.
It is an indication that the command is just an example and you have to complete it with actual values.
Another thing to note here is that some tutorials show command examples that start with $ like this:
This is a way for them to indicate that it is command (not command output). But many new Linux users copy the preceding $ along with the actual command and when they paste it in the terminal, it throws an error, obviously.
So, when copying some commands, don’t copy the $ if it is at the beginning. You should also avoid copying random commands for random websites specially when you do not understand what it does.
Since you are reading about copying commands, when you see commands in multiple lines together, you should copy one line at a time and run them one by one:
The following section tells you how to run multiple commands in one go.
16. You can run multiple commands at once
You can run multiple commands at once without user intervention. You might have seen it already as an Ubuntu user in the form of this command:
sudo apt update && sudo apt upgrade
There are three different ways to combine commands in the terminal:
|;||Command 1 ; Command 2||Run command 1 first and then command 2|
|&&||Command 1 && Command 2||Run command 2 only if command 1 ends sucessfully|
|||||Command 1 || Command 2||Run command 2 only if command 1 fails|
17. Stop a running Linux command
If a Linux command is running in the foreground, i.e., it is showing output or you cannot enter any other command, you can stop it using the Ctrl+C keys.
I discussed it previously. It comes from the legacy computing days of UNIX.
So, the next time you see a command like top or ping running continuously and you want the terminal control back, just use these two keys:
18. Clear the terminal
When I find that my screen is too cluttered with different kinds of output, I clear the terminal screen before starting some other work. It is just a habit but I find it helpful.
To clear the terminal, use the command:
You may also use Ctrl+L terminal shortcut.
19. Exiting the terminal
In a few cases, I have seen people closing the terminal application to exit the session. You could do that but the proper way to exit a terminal is to use the exit command:
You may also use the keyboard shortcut Ctrl+D for Ubuntu terminal.
There are so many additional stuff you can do in the terminal even if you are new to the entire terminal thing. You can:
And if you are looking for more, take a look at these Linux command tips and use the terminal like a pro.
Getting familiar with the basic commands is also highly recommended.
Honestly speaking, there is way too much to talk about. It is difficult to determine what should be considered absolute basics and what should be left out. For example, I wanted to avoid including the information about paths because it needs detailed explanation but going too much into detail on a single could be overwhelming.
I have passed the stage where small things used to baffle me in the terminal. If you are new to the Linux terminal or remember the struggle from your initial Linux days, feel free to suggest any additions to the list. I might update the list with your input.
And if you learned something new, please do mention it in the comments. I would like to see if this article was worth the effort :)