You are on page 1of 47

1.

Installing Ubuntu on Virtual Box or VMware


System Configuration of the Host Machine

In order to install Ubuntu on Virtual Box, you should have a physical computer with at
least 4 GB of RAM (Random Access Memory), a hard disk drive with at least 30 GB of free
space (SSD is preferred due to its higher performance). Your CPU (Central Processor
Unit) must support Intel VT-x or AMD-v hardware virtualization features which must also
be enabled in UEFI/BIOS. This point is especially important if you are looking for how to
install Ubuntu 64-bit on Virtual Box.

Virtual Box
Virtual Box is a free, open-source and cross-platform software that lets you create,
run, and manage virtual machines on your system. Virtual Box was originally
developed by Innotek GmbH and released in 2007. The company was later bought by
Sun Microsystems. With Oracle VM VirtualBox you can create one or more VMs on a
single physical server. Virtual machines are computers that use the hardware
components of the host computer, each running its own operating system. VB
supports the installation of MS Windows, Linux, BDS, and MS-DOS on the installed
VMs.

Install Virtual Box


Open the Virtual Box website. Go to https://www.virtualbox.org/wiki/Downloads in
your computer's Internet browser. This is the website from which you'll download the
Virtual Box setup

TYBCA Linux
Open the Virtual Box EXE file. Go to the location to which the EXE file downloaded
and double-click the file. Doing so will open the Virtual Box installation window.
Navigate through the installation prompts.
 Click next on the first three pages.
 Click yes when prompted.
 Click Install
 Click yes when prompted.

Click Finish when prompted. It's in the lower-right side of the window. Doing so


will close the installation window and open VirtualBox. Now that you've installed
and opened VirtualBox, you can create a virtual machine in order to run any
operating system on your PC.

TYBCA Linux
Downloading the Installation Image
You need to download the Ubuntu distribution for installing Ubuntu on
VirtualBox. Go to the official Ubuntu website and download the necessary
version of the Ubuntu installer. Let’s download Ubuntu 20.04.2.0 LTS – this is the
latest long term support (LTS) Ubuntu version available at this moment. Five-
year support is provided for Ubuntu LTS distributions (both Ubuntu Desktop and
Ubuntu Server). Ubuntu LTS is more widely tested, enterprise-focused and
compatible with new hardware.
Click the green Download button and save the ISO file to the custom location. In
our case, the file name is ubuntu-20.04.2.0-desktop-amd64.iso. Ubuntu 18 is
provided only as 64-bit editions.

Creating a Virtual Machine


1. Open VirtualBox. Double-click (or click once on a Mac) the VirtualBox app icon.
2. Click New. It's a blue badge in the upper-left corner of the VirtualBox window.
Doing so opens a pop-up menu.

TYBCA Linux
6. Enter a name for your virtual machine. Type whatever you want to name your
virtual machine (e.g., Ubuntu) into the "Name" text field that's near the top of
the pop-up menu.
7. Select Linux as the "Type" value. Click the "Type" drop-down box, then
click Linux in the resulting drop-down menu.
8. Select Ubuntu as the "Version" value. Ubuntu should be selected by default
after you set the "Type" value to Linux, but if it isn't, click the "Version" drop-
down box and click Ubuntu (64-bit) before proceeding.

4. Click Next. It's at the bottom of the menu.


5. Select an amount of RAM to use. Click and drag the slider left or right to
decrease or increase the amount of RAM that VirtualBox will have available for
your Ubuntu virtual machine.
 The ideal amount of RAM will automatically be selected when you get to this page.
 Make sure not to increase the RAM into the red section of the slider; try to keep
the slider in the green.

TYBCA Linux
10. Click Next. It's at the bottom of the menu.
11. Create your virtual machine's virtual hard drive. The virtual hard drive is a
section of your computer's hard drive space which will be used to store your
virtual machine's files and programs:
 Click Create
 Click Next
 Click Next
 Select an amount of space to use.
 Click Create

TYBCA Linux
Installing Ubuntu
1. Select your new virtual machine and click 'Settings' button.
2. Click on 'Storage' category and then 'Empty' under Controller:IDE. Click "CD/DVD"
icon on right hand side and select the ubuntu ISO file to mount.
12.

TYBCA Linux
3. Click Start button.

TYBCA Linux
5. Once the new VM is prepared for installing Ubuntu on VirtualBox, start the VM
(Machine > Start). The VM boots from the ISO Ubuntu installation image. The first
screen that you can see after booting is the Welcome screen.

4. In the left pane select Language for displaying information in the installer


interface. English is selected in the current example. Then click Install Ubuntu.

TYBCA Linux
6. Keyboard layout. Choose your keyboard layout. Let’s select English (US).

7. Updates and other software. There are a few options to choose from on this
screen.
Normal installation. A web browser, utilities, office applications and media players
are installed.
Minimal installation. Only the main components including a web browser and basic
utilities are installed.
Let’s select the normal installation.
8. Installation type. This screen contains options for preparing a disk for Ubuntu
installation.
Erase disk and install Ubuntu. This is the default option. All disk space will be
automatically allocated to Ubuntu. If you select Erase disk and install Ubuntu on
VirtualBox VMs, one big /dev/sda1 partition is created on /dev/sda.
This /dev/sda1 partition with ext4 file system is mounted to the / directory (root
directory), though a separate swap partition is not created. Attention: All data on
the virtual disk will be erased—there is no reason to worry about it, however,
because an empty virtual disk created previously is being used for installing
Ubuntu on VirtualBox.
9. Setting up Ubuntu
 Select a time zone.
 Enable the on-screen keyboard
 Enable the on-screen keyboard
 Enter your name, enter a username, and create a password.
 Wait for Ubuntu to finish installing.
 Restart the virtual machine.
 Log into your computer.
TYBCA Linux
TYBCA Linux
2. Basic Linux Commands
1. ls
Directory listing

2. ls –al
Formatted listing with hidden filesDirectory listing

3. cd dir
Change directory to dir

TYBCA Linux
4. ls -lt
Sorting the Formatted listing by time modification

6. Cd
Change to home directory

5. pwd
Show current working directory

TYBCA Linux
7. mkdir dir
Creating a directory dir

8. cat >file
Places the standard input into the file

9. more file
Output the contents of the file

TYBCA Linux
10. head file
Output the first 10 lines of the file

11. tail file


Output the last 10 lines of the file

TYBCA Linux
12. tail -f
file Output the contents of file as it grows,starting with the last
10 lines

TYBCA Linux
14. touch file
Create or update file

13. rm file
Deleting the file

TYBCA Linux
15. rm -r dir
Deleting the directory

16. rm -f file
Force to remove the file

18. rm -rf dir


Force to remove the directory dir

17. cp file1 file2


Copy the contents of file1 to file2

TYBCA Linux
19. cp -r dir1 dir2
Copy dir1 to dir2;create dir2 if not present

25.mv file1 file2


Rename or move file1 to file2,if file2 is an existing directory

20.date
Show the current date and time

21. cal
Show this month's calender

22. uptime
Show current uptime

23.w
Display who is on line

24.whoami
Who you are logged in as

TYBCA Linux
26.uname -a
show kernel information
27. cat /proc/cpuinfo
cpu information
28.man command
show the manual for command

TYBCA Linux
TYBCA Linux
3. Advance Linux Commands
1. ps
To display the currently working processes

2. top
Display all running process

TYBCA Linux
3. kill pid
Kill the process with given pid

4. File permission
chmod octal file
Change the permission of file to octal,which can be found
separately for user,group,world by adding,
• 4-read(r)
• 2-write (w)
• 1-execute(x)

TYBCA Linux
5. Searching
grep pattern file
Search for pattern in file

6. grep -r pattern dir


Search recursively for pattern in dir

7. command | grep pattern


Search pattern in the output of a command

TYBCA Linux
8. locate file
Find all instances of file

9. find . -name
filename Searches in the current directory (represented by a
period) and below it, for files and directories with names
starting with filename

TYBCA Linux
4. Install and work with c & c++

Requirements
Privileged access to your Ubuntu System as root or via  sudo  command is
required.

Conventions
 # - requires given linux commands to be executed with root privileges either
directly as a root user or by use of  sudo  command
 $ - requires given linux commands to be executed as a regular non-
privileged user

Install C++ on Linux


You can easily install C++ on Linux, just follow these steps-

1. install g++ compiler using a terminal in Linux


Our first step would be to open the terminal. The terminal icon might be on your
desktop screen. If not, you can find it on the search menu. Another alternative to
open terminal is a shortcut: Press Ctrl + Alt + T simultaneously.

 The second step would be to type the command: sudo apt -get install g+
+. It is important to note that g++ is the name of the C++ compiler.

TYBCA Linux
 If you have the permission to install the g++ compiler, a set of statements
like this would appear. The installation would automatically begin.

 You would get a message: “Do you want to continue?” Press ‘y’ in order to
continue. This is what your screen would look like after you press ‘y’.

TYBCA Linux
check the version of C++
The following command would help you find out the version of the g++ compiler
that you processed to install C++.

g++ — version

TYBCA Linux
compile and run C++ program
We have now created a C++ program with the program name as test.cpp. It is now
time to run and compile and run the code using the terminal.

The ‘g++’ command will help you throughout your coding journey. It is a very
important command that comes pre-installed on your latest Ubuntu version.

To compile the code, we use the g++ command.:

g++ program.cpp -o program

TYBCA Linux
Here, the g++ command is followed by the file name with the .cpp extension and ‘-
o’ and the name of the executable file, which is, ‘program’ in this case.
Key takeaway: The executable file name can be different from the source file
name
To run the program, use the command:

./program
Here, the period symbol ‘.’ followed by a backslash is followed by the name of the
executable file, that is, ‘program’ in this case.

compile and run C program


We have now created a Cprogram with the program name as test2.c. It is now
time to run and compile and run the code using the terminal.

TYBCA Linux
Compile the C program with gcc Compiler
In your Terminal, enter the following command in order to make an executable
version of the program you have written:

Syntax:

$ gcc [programName].c -o programName

Example:

$ gcc test2.c -o test2

Run the program


The final step is to run the compiled C program. Use the following syntax to do so:

$ ./programName

Example:

$ ./text2

TYBCA Linux
5. Working with Vi, nano, gedit editors.
Command:vi filename

Eg:vi my_file.txt

:wq:command is for save and quit

TYBCA Linux
Nano Editor
explain the basic usage of the nano editor, including how to create and open a
file, edit a file, save a file, search and replace text, cut and paste text, and more.
To create new file
When you decide to exit (Ctrl+X), it will ask whether to save or discard the file.
If you press y to save the file, it will ask you to name the file. Type in a name and
press Enter.
Syntax: nano [filename]
Output :

TYBCA Linux
gedit
Text Editor (gedit) is the default GUI text editor in the Ubuntu operating system.
It is UTF-8 compatible and supports most standard text editor features as well
as many advanced features. These include multilanguage spell checking, extensive
support of syntax highlighting, and a large number of official and third party
plugins.
gedit is suited for both basic and more advanced text editing and is released
under the GNU General Public License.
Opening gedit
gedit incorporates a graphical user interface (GUI) and is opened by going
to Applications → Accessories → Text Editor or by pressing Alt+F2 and
typing gedit

TYBCA Linux
6. Working with file and directories permissions

View Check Permissions in Linux


To start with file permissions, you have to find the current Linux permission settings.
There are two options to choose from, depending on your personal
preference: checking through the graphical interface or using the command.

Check Permissions using GUI


Finding the file (directory) permission via the graphical user interface is simple.

1. Locate the file you want to examine, right-click on the icon, and select Properties.

2. This opens a new window initially showing Basic information about the file.


Navigate to the second tab in the window, labeled Permissions.

3. There, you’ll see that the permission for each file differs according to three
categories:

Owner (the user who created the file/directory)

Group (to which the owner belongs to)

Others (all other users)

TYBCA Linux
Check Permissions in Command-Line with Ls Command
If you prefer using the command line, you can easily find a file’s permission settings
with the ls command, used to list information about files/directories. You can also
add the –l option to the command to see the information in the long list format.
To check the permission configuration of a file, use the command:

ls –l [file_name]

For instance, the command for the previously mentioned file would be:

ls –l raj.txt

As seen in the image above, the output provides the following information:

 file permission

 the owner (creator) of the file

 the group to which that owner belongs to

 the date of creation.

It shows the permission settings, grouped in a string of characters (-, r, w, x)


classified into four sections:

1. File type. There are three possibilities for the type. It can either be a regular file

TYBCA Linux
The characters r, w, and x stand for read, write, and execute.
The categories can have all three privileges, just specific ones, or none at all
(represented by  –, for denied).

Users that have reading permission can see the content of a file (or files in a
directory). However, they cannot modify it (nor add/remove files in a directory). On
the other hand, those who have writing privileges can edit (add and remove) files.
Finally, being able to execute means the user can run the file. This option is mainly
used for running scripts.

Using Chmod Command to Change File Permissions 


As all Linux users, you will at some point need to modify the permission settings of a
file/directory. The command that executes such tasks is the chmod command.

The basic syntax is:

chmod [permission] [file_name]

There are two ways to define permission:

1. using symbols (alphanumerical characters)

2. using the octal notation method

Define File Permission with Symbolic Mode


To specify permission settings using alphanumerical characters, you’ll need to define
accessibility for the user/owner (u), group (g), and others (o).

Type the initial letter for each class, followed by the equal sign (=) and the first letter
of the read (r), write (w) and/or execute (x) privileges.

To set a file, so it is public for reading, writing, and executing, the command is:

chmod u=rwx,g=rwx,o=rwx [file_name]

To set permission as in the previously mentioned test.txt to be:


• read and write for the user
• read for the members of the group
• read for other users

TYBCA Linux
Use the following command:

chmod u=rw,g=r,o=r raj.txt

Another way to specify permission is by using the octal/numeric format. This option is
faster, as it requires less typing, although it is not as straightforward as the previous
method.

Instead of letters, the octal format represents privileges with numbers:


 r(ead) has the value of 4
 w(rite) has the value of 2
 (e)x(ecute) has the value of 1
 no permission has the value of 0

The privileges are summed up and depicted by one number. Therefore, the
possibilities are:
 7 – for read, write, and execute permission
 6 – for read and write privileges
 5 – for read and execute privileges
 4 – for read privileges

As you have to define permission for each category (user, group, owner), the
command will include three (3) numbers (each representing the summation of
privileges).
For instance, let’s look at the test.txt file that we symbolically configured with
the chmod u=rw,g=r,o=r test.txtcommand.

The same permission settings can be defined using the octal format with the
command:

TYBCA Linux
TYBCA Linux
7. Shell Scripting
Shell Scripting is an open-source computer program designed to be run by the
Unix/Linux shell. Shell Scripting is a program to write a series of commands for the
shell to execute. It can combine lengthy and repetitive sequences of commands into
a single and simple script that can be stored and executed anytime which, reduces
programming efforts.

What is Shell?
Shell is a UNIX term for an interface between a user and an operating system service.
Shell provides users with an interface and accepts human-readable commands into
the system and executes those commands which can run automatically and give the
program’s output in a shell script.

An Operating is made of many components, but its two prime components are –

 Kernel
 Shell

Types of Shell
There are two main shells in Linux:

1. The Bourne Shell: The prompt for this shell is $ and its derivatives are listed below:

 POSIX shell also is known as sh


 Korn Shell also knew as sh
 Bourne Again SHell also knew as bash (most popular)

2. The C shell: The prompt for this shell is %, and its subcategories are:

 C shell also is known as csh


 Tops C shell also is known as tcsh

TYBCA Linux
How to Write Shell Script in Linux/Unix
Shell Scripts are written using text editors. On your Linux system, open a text editor
program, open a new file to begin typing a shell script or shell programming, then give
the shell permission to execute your shell script and put your script at the location from
where the shell can find it.

Let us understand the steps in creating a Shell Script:

1. Create a file using a vi editor(or any other editor).  Name  script file


with extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh

"#!" is an operator called shebang which directs the script to the interpreter location. So,
if we use"#! /bin/sh" the script gets directed to the bourne-shell.

Let's create a small script –

#!/bin/sh
ls

TYBCA Linux
Adding shell comments
Commenting is important in any program. In Shell programming, the syntax to add a
comment is

#comment

Let’s create

(#sample scripting) is the comment

It ignores the comment in output

TYBCA Linux
Shell Variables
As discussed earlier, Variables store data in the form of characters and numbers.
Similarly, Shell variables are used to store information and they can by the shell only.

For example, the following creates a shell variable and then prints it:

variable ="Hello"
echo $variable

Below is a small script which will use a variable.

#!/bin/sh
echo "what is your name?"
read name
echo "How do you do, $name?"
read remark
echo "I am $remark too!"

TYBCA Linux
TYBCA Linux
8. Working with loops and conditional statements

Looping Statements in Shell Scripting: There are total 3 looping statements which


can be used in bash programming
1. while statement
2. for statement
3. until statement
To alter the flow of loop statements, two commands are used they are,
1. break
2. continue
Their descriptions and syntax are as follows:
 while statement
Here command is evaluated and based on the result loop will executed, if
command raise to false then loop will be terminated
Syntax
while command
do
Statement to be executed
Done

Implementing while loop

TYBCA Linux
for statement
The for loop operate on lists of items. It repeats a set of commands for every item
in a list.
Here var is the name of a variable and word1 to wordN are sequences of
characters separated by spaces (words). Each time the for loop executes, the
value of the variable var is set to the next word in the list of words, word1 to wordN.
Syntax

for var in word1 word2 ...wordn


do
Statement to be executed
done

TYBCA Linux
until statement
The until loop is executed as many as times the condition/command evaluates to false.
The loop terminates when the condition/command becomes true.
Syntax
until command
do
Statement to be executed until command is true
done

TYBCA Linux
Conditional Statements: There are total 5 conditional statements which can be used
in bash programming
1. if statement
2. if-else statement
3. if..elif..else..fi statement (Else If ladder)
4. if..then..else..if..then..fi..fi..(Nested if)
5. switch statement
Their description with syntax is as follows:
if-else statement
If specified condition is not true in if part then else part will be execute.
Syntax
if [ expression ]
then
statement1
else
statement2
fi

TYBCA Linux

You might also like