The terminal, also known as the command line interface, is a powerful tool for interacting with a computer’s operating system. While graphical user interfaces (GUIs) are more common, the command line interface provides greater control and flexibility. Ubuntu is a popular Linux-based operating system that comes with a terminal built-in. If you’re new to Ubuntu or the command line interface, this article will help you get started with the basics. Ubuntu is available in three primary flavors.
- Ubuntu Desktop
- Ubuntu Server
- Ubuntu Core: Designed and developed for the Internet of Things (IoT)
One popular utility that you will find in all these Ubuntu three editions is the Terminal or Command-line. This post will have an in-depth look at the Ubuntu terminal, Linux shells, and the basic commands you need to know as you get acquainted with Linux systems.
The Ubuntu Terminal
The Terminal is a command line interface that allows you to interact with your computer in a text-based environment. Unlike graphical user interfaces where you control your PC by clicking on graphical objects displayed on the screen, the Terminal allows you to perform tasks on your system by running commands.
At first, using the Terminal can seem daunting and overwhelming, mainly if you are used to working with graphical interfaces. However, once you get the hang of it, the Terminal can be a powerful tool that can significantly enhance your productivity and efficiency.
The Terminal allows you to perform various tasks, from navigating your file system, installing and managing software, running scripts, and automating tasks. In addition, it gives users complete control over their computers, allowing them to customize your system to their needs.
When using the Terminal, you will be working with the command line, a text-based interface that allows you to enter commands and receive feedback from the computer. These commands can perform various tasks, from simple file management to more complex tasks like networking and system administration.
Opening a Terminal
You can use two ways to open the Terminal on your Ubuntu system.
- Graphical method
- Keyboard shortcut
Graphical method: Click the “Activities” button at the top-left and type “Terminal” in the search box that appears. You will see the Terminal application listed below. Click on the app to launch it.
Keyboard shortcut: This is one of the quickest methods of opening the Terminal on your Ubuntu system. Use the keyboard shortcuts Ctrl + Alt + T.
Understanding Shells in Linux
Ubuntu, like most Linux distributions, comes with several different shells, which are programs that provide a command-line interface for interacting with the operating system. Here are some of the most common shells available on Ubuntu:
Bash (Bourne-Again SHell): This is the default shell on most Linux distributions, including Ubuntu. It is a popular shell because of its powerful scripting capabilities and support for command-line history and tab completion.
Zsh (Z Shell): This extended version of Bash includes many additional features, such as advanced tab completion and spelling correction.
Fish (Friendly Interactive SHell): This modern shell is designed to be easy to use and customize. Some popular features of the Fish shell are syntax highlighting and auto-suggestions.
Dash (Debian Almquist SHell): This lightweight shell is optimized for speed and low memory usage. It is often used for system scripts and is the default shell for some Ubuntu distributions.
Csh (C SHell): This is an older shell similar to the Bash shell but with a different syntax. The C-shell supports powerful features like command-line editing and job control.
Know which shell you are using?
You can check which shell you are currently using on your Ubuntu system by running the following command in a terminal window:
echo $SHELL
This command will display the path to the shell program currently running on your system. For example, if you are using the Bash shell, the output will be:
/bin/bash
If you use a different shell, such as Zsh or Fish, the output will show the path to that shell program instead.
Customizing the Ubuntu Terminal Prompt
The Ubuntu Terminal prompt is the text that appears before the cursor when using the command-line interface—the prompt displays your username, hostname, and current working directory by default.
You can customize the Terminal prompt by modifying the value of the PS1 environment variable. The PS1 variable contains the text that is displayed as the prompt.
Let’s look at some of the various ways you can use to customize your Terminal prompt.
1. Changing the color of the prompt:
PS1="\[\e[32m\]\u@\h:\w\$\[\e[0m\] "
This will set the prompt to display your username and hostname in green, followed by the current working directory and a $ symbol in green.
2. Adding the current time to the prompt:
PS1='\u@\h \[\e[33m\]\A\[\e[0m\] \w\$ '
This will set the prompt to display your username and hostname, followed by the current time in yellow, the working directory, and a $ symbol.
3. Removing the hostname from the prompt:
PS1='\u:\w\$ '
This will set the prompt to display only your username and current working directory, followed by a $ symbol.
Note: Add the appropriate PS1 command to your .bashrc file in your home directory to make these changes permanent. This file is executed every time you start a new Terminal session, so any changes you make to the PS1 variable will be applied automatically.
Basic Linux commands for beginners
Now that you have a solid understanding of how the Ubuntu command line works, let’s look at some of the most popular commands you can use to perform your day-to-day tasks.
1. The ls command
The ls command lists the contents of a directory on the Terminal. When you execute the ls command alone without any additional arguments, it will list the contents of the current directory. You can list the contents of other directories by passing the path to these directories, as shown below.
ls #Lists contents of the current directory
ls Desktop #Lists contents of the Desktop
ls /var/www #Lists contents of the /www directory
Some of the popular arguments used with the ls
command are -l
and -a
ls -l
command: This command is used to list directories and files together with additional information like permissions, owner, size, and when it was last modified.ls -a
command: This command lists the contents of a directory together with the hidden file. Hidden files in Linux start with the dot (.) character.
2. The cd command
The cd
command is used to navigate to a different directory or change the current working directory. For example, if you wanted to navigate to the Desktop, you would use the command below.
cd Desktop
You can also navigate to a directory that is not in your current working directory by passing the path of that directory, as shown below.
cd /etc/
To navigate to the previous (parent) directory, use the cd
command with double dots, as shown below.
cd ..
3. The mkdir command
The mkdir
command is used to create a new directory on your system. For example, use the command below to create a ” myfolder ” directory in your current working directory.
mkdir myfolder
You can also create a directory inside a directory by passing the path to that directory. For example, the command below will create a ” Movies ” directory inside the “Downloads” directory.
mkdir /Downloads/Movies
You can also create multiple directories at once by passing their names to the mkdir command
as shown below.
mkdir dir_1 dir_2 dir_3
Check out our comprehensive guide on the ls command – 13 ways to use the ls command to list files on Linux.
4. The rm command
The rm
command is used to delete a file on your system. Keep note that this command will permanently delete a file from your system. For example, use the command below to delete a file called “file_one” on your system.
rm file_one
You can also remove multiple directories by passing their names to the rm command, as shown below.
rm file_one file_two
If you want to delete everything in a directory, you can use the rm command
with an asterisk (*).
rm *
The rm
command alone cannot delete a directory. You will need to pass the -r argument as shown below.
rm -r my_folder
5. The rmdir command
The rmdir
command is used to delete an empty directory on your system.
rmdir my_directory
6. The touch Command
The touch command creates a new empty file on your system. For example, the command below will create a file called index.html in your current working directory.
touch index.html
You can create multiple files using the touch command by passing their names to the command, as shown below.
touch file_one file_two file_three
7. The cat command
The cat command is used to reveal/ display the contents of a file on the Terminal. For example, to view the contents of the /etc/hosts file without making any changes, you can use the command below.
cat /etc/hosts
8. The cp command
As the name suggests, the cp command performs copy-and-paste actions on the Terminal. For example, the command below will copy the “index.html” file in your current working directory to the Desktop.
cp index.html Desktop/
9. The mv command
The mv command moves a file or directory from one location to another. For example, the command below will move the “movies” directory from “Downloads” to the “Desktop.”
mv movies /home/fosslinux/Desktop/
10. The chmod command
The chmod
command is used to set file or directory permissions on Ubuntu. One of the core features behind Linux security is permissions. Every file or directory on Ubuntu has specific permissions for the owner (who created the file), group (the group the owner belongs to), and other users.
For example, the command below will give the owner, group, and other users read, write and execute permissions on the “index.html” file.
chmod 777 index.html
Check out our comprehensive posts on file permissions on Linux systems – Linux File Permissions: Everything You Need to Know.
11. The sudo command
Also known as the magic command, the sudo
command executes other commands using administrator /root privileges. For example, you need admin privileges to update or upgrade your Ubuntu system. Therefore, you will need to write the update command as shown below.
sudo apt update
Conclusion
The Ubuntu Terminal is a powerful tool that allows you to control your computer through text commands, providing users complete control over their system. While it may seem daunting initially, with some practice and familiarity, the Terminal can significantly enhance your productivity and efficiency.
Ubuntu comes with several different shells, each with its own set of features, and you can quickly check which shell you are using with a simple command. Additionally, you can customize your Terminal prompt to suit your preferences and make it easier to navigate the command line.
Finally, we covered some basic Linux commands for beginners that you can use to perform your day-to-day tasks, such as listing directory contents, creating and deleting files and directories, and manipulating file permissions.
By mastering the Ubuntu Terminal, you can take full advantage of the power and flexibility of Linux, making it an excellent choice for developers, system administrators, and power users.
1 comment
thanks alot of informtion goodjobs….