Getting Started With Ubuntu and Bash Shell
Ubuntu is a free, open-source operating system and a distribution of Linux that you can install on your laptop or desktop.
Join the DZone community and get the full member experience.
Join For FreeIntroduction
Ubuntu is a free, open-source operating system that you can install on your laptop or desktop. It comes in desktop and server versions. Ubuntu is easy to install, simple to use, safe, secure, fast, and massively powerful.
Ubuntu is a distribution of Linux. The Linux kernel is at the core of the operating system and it does all the essential low-level stuff.
Other distributions of Linux you may have heard of are Redhat, Suse, CentOS, Andriod, etc.
Ubuntu is based on Debian (another Linux distro) and Ubuntu itself has some other flavors e.g. Kubuntu and Linux Mint e.g.
Why Ubuntu
- Security
- Customizable
- Easy to administer, e.g. run jobs, disk management, etc.
- Open Source/Free
- Can run efficiently on cheap hardware
Installing Ubuntu
Installing Ubuntu is very easy and you can download the software from the official website. There, you can find detailed information about the installation process. You can install it on your laptop, and Ubuntu-desktop comes with a nice UI.
Ubuntu-server also has the same core, but it is lean and does not come with a UI. It's ideal for running background processes e.g. running a web-server, database server, etc. I will be using this for the examples.
The other route you can take is to use cloud services. I created an ubuntu-server virtual machine on Azure, and the following screenshot shows part of that step:
Once the VM is set up and running, I opened a git-bash terminal on my windows machine (I had git installed on my windows machine so I can use its bash shell, and my windows machine acts as a client and can access the ubuntu-server on Azure cloud). The following picture shows that I am connected to Ubuntu VM:
Now you can see the prompt has changed to reflect my user-name and computer name: ~ is a special character telling that I am at the home directory, and at this point, I can start writing bash commands, which we will see next.
Using the Command Line
In the rest of the article, I will focus on the command line. Though Ubuntu desktop is very interesting and you can explore it easily by using it.
Command line is a different way of working with your computer instead of graphical representation like windows, icons, etc.
You can access the command line by running the terminal app. Bash is the default terminal in Ubuntu.
There are a lot of Linux commands, and you may be using some more than others. Don’t worry if you can not remember the command syntax, me neither. As long as you understand the concepts, you can always search online to find the syntax and related examples. Now, we will see a few of the bash commands:
UserName and HostName
whoami //outputs the username
hostname //outputs the computer name
Working With Files/Folder
>>ls command lists the files in the current directory.
>>ls -l command outputs the long list of directory contents:
This output tells me each entry whether it is file or directory (d for directory), what different users are allowed to do with it, who owns it, size, and when it was last changed.
Using ls, we can list the contents of different directory as shown below:
We can also filter entries using wild-cards etc as shown below:
In Linux, everything is a file. Even your computer memory and network connections are files, and every file has that set of possible permissions.
Getting and Applying Updates
xxxxxxxxxx
sudo apt-get update && sudo apt-get upgrade
This command will update your operating system.
pwd
pwd (print working directory) shows the current directory (basically, the folder) you’re in.
cd
Allows you to change directory.
Typing cd alone without any argument (without anything that follows it) will bring you to the home directory of the user.
cd followed by a dash (–) will bring you to the recent directory you were in.
mkdir
mkdir (make directory) is used to create a directory.
Check for the Distribution
You can check the distribution and version info by using following command:
xxxxxxxxxx
cat /etc/issue
echo
Echo prints out whatever you say to it.
You can redirect the output to a file by the following method:
grep
grep is an extremely powerful tool to search the content of a file. It prints out the line containing the word(s) specified if it is present in the file. For example:
Summary
Getting started with Ubuntu is easy, and in this post, we took some small steps towards this learning journey. We can quickly start with it, and we saw a few of the bash commands. Ubuntu is fast, open-source, and ideal for running background processes. We will look few of those processes in the next articles. Till next time, happy learning.
Published at DZone with permission of Jawad Hasan Shani. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments