Tutorial 16 Basic Linux Commands
Tutorial 16 Basic Linux Commands
Tutorial 16
Basic Linux Commands
This tutorial takes you through the process of installing and using VirtualBox to create and use
a Debian Linux distribution. In addition, the tutorial takes you through the process of executing
basic tasks on it using Linux commands.
We will use a Debian Linux distro during this. Debian is one of the most popular and powerful
GNU distros which is considered an excellent choice for server environments. Debian has also
been used as the base for many specialist distributions such as Ubuntu, Xandros, Knoppix.
2. Download the 64-bit version of Debian Linux by clicking on the amd64 link that can be found
under the Small CDs or USB sticks section of the webpage. The file was called debian-12.2.0-
amd64-netinst.iso at the time of writing and is around 628MB.
Note: You can similarly download other distributions of Linux and install them.
Week 8
Computer Systems
2. Firstly, you need to configure the virtual machine by identifying its name, OS type and
version, and the memory and hard disk sizes allocated to it. Thus, name the new virtual
machine as Debian and change the type to Linux and the version to Debian (64bit) and
click Next as shown in the figure.
3. Proceed with the default values for the Base Memory of 2048 MB and click Next. Then,
proceed with the default values to “Create a Virtual Hard Disk Now” with a Disk Size
of 20.00 GB and click Next and then Finish as shown in the figures.
Week 8
Computer Systems
4. Now, you have completed the configuration of the virtual machine and hence the virtual
machine name Debian appears on the left side part of the VirtualBox as shown in the figure.
5. Secondly, you need to install the Debian Linux and configure Linux distro itself. Thus, click
the Start button. As you have not yet installed Debian, the VirtualBox responded by
clarifying that “The virtual machine failed to boot” and asking for the install DVD for the
Debian operating system. So, you need to use the image file (debian-12.2.0-amd64-
netinst.iso) that you have downloaded in Section 1 as shown in the figure.
6. Once the server has been booted, you will be asked to choose the installation option. Choose
the Graphical install option and press enter as shown in the figure.
Week 8
Computer Systems
7. You might have already noticed that the size of the Debian virtual machine is too small which
does not enable you to read its contents and follow up the installation. You can increase the
window size of the virtual machine by selecting the command Scaled Mode from the View
menu and click on Switch to confirm as shown in the figure.
8. Once you have selected the type of installation, to complete it you need to perform the
following actions:
1) Choose the English language from the list provided and then click on Continue.
2) When asked for the selected location, choose the United Kingdom as this will be used for
the time zone. Click Continue for the next step.
3) For the keyboard layout choose the British English option (American English if your
keyboard is compatible with US English) and click Continue.
4) Set the hostname of the server to a name of your preference. In this example, the
hostname debian will be used. Then click on Continue to proceed to the next step.
Week 8
Computer Systems
5) Set the domain name could be set to .local, then just click Continue.
6) Now you will be prompted to set the root password. Type in a password that you will
remember and the retype it to confirm the password and click Continue. [It is
recommended to use a simple password such as 123 for the purpose of the study to avoid
forgetting it later].
7) Next, you need to type in a Full name of a user account for the non-administrative user
account. [It is recommended to type user1 to have the same exact screenshots available in this
document and because you will create other users in the next tutorial. Otherwise, you can use a name
of your preference that is easy to remember] and click Continue to proceed.
8) Now, you are prompted to select a username for the new user account (recommended to
leave the default username user1) and click Continue to proceed.
9) Then, you will be asked to set the password for the new user account. Type in a password
that you will remember and then retype it to confirm the password. [It is recommended
to use a simple password such as 123 for the purpose of the study to avoid forgetting it
later].
10) For the Partition disks, choose the default option Guided – use entire disk option and
click Continue.
11) Next, select the default option SCSI1 and click Continue. Then, select the default option
All files in one partition and proceed to the next step by clicking Continue again. Then,
select the default option Finish partitioning and write changes to disk and complete
the partitioning process by clicking on the Continue button. Finally, confirm the changes
by selecting the Yes option that will allow the system to write those changes to the disks.
To move to the next step, click on Continue.
12) When you are asked whether you wish to scan extra installation media, select the default
option No and click Continue.
13) To configure the package manager, select the default option United Kingdom that will
find a mirror of the Debian archive on the respective network and hit Continue. Then,
choose the mirror ftp.uk.debian.org from the list and click Continue.
14) For the HTTP proxy, leave it blank and click Continue to proceed.
15) Finally, answer No to the question “Participate in the package usage survey?” and
click Continue.
16) In this step, you are required to choose the installation of additional software packages.
To install some useful software, leave the default option as they are and then click the
Continue button.
17) Furthermore, you need to install the GRUB boot loader by choosing Yes and then clicking
Continue to proceed. Finally, select the option /dev/sda from the list and click Continue
for the completion of the installation.
Debian Linux distro with a graphical environment is now installed and you can shut the system
down by closing the window and selecting the option Power off the machine and click OK.
Later, and you can boot up the virtual machine anytime using the start button on the VirtualBox.
Week 8
Computer Systems
1. You have installed a Debian Server with GUI (Debian Desktop). You need to install a Debian
Server without GUI (Debian Server with Command Prompt) which you can name it as
Debian CP (we will use it in the next tutorials).
2. Repeat the commands that you have completed in the previous sections on the new Debian
CP server.
Note: For the Debian virtual machine, you need to log into the machine, then click on
Activities tab in the top left and type Terminal in the search box in the top middle.
Once you find it, open it to enable the writing of the Linux commands.
Week 8
Computer Systems
Note: There are some special directories such as single dot (.), double dots (..) and tilde
(~). While (.) refers to the current directory and (..) refers to the parent directory
respectively, (~) refers to the home directory. So, for example, the command cd .. takes
you one directory up the hierarchy.
Now, let us start by navigating to the root (/) directory and exploring the top-level directories.
The cd (change directory) command takes a single argument, the directory you want to
navigate to root (/) directory, this can be done by typing cd /. The ls (list) command lists all the
files and directories in the current working directory.
Use the cd command to navigate to the /bin directory. Use the ls command to list the contents.
The command cp (copy) makes a copy of file1 which is located at the pathname of the first
argument into file2 which is located at the pathname of the second argument. To make 2 copies
of the file hostname which is stored at the directory /etc into the recently created directory
My_Docs and the current working directory, type the following commands:
cd ~
cp /etc/hostname ~/My_Docs
cp /etc/hostname .
Week 8
Computer Systems
The command mv (move) file1 which is located at the pathname of the first argument into file2
which is located at the pathname of the second argument. The command is used to either moves
a file from a directory to another or rename a file if both files are in the same directory. To move
the file hostname into the /tmp directory and then rename it as new, type the following
command:
mv hostname /tmp/hostname
mv /tmp/hostname /tmp/new
The command rm (remove) file1 which is located at the pathname of the first argument while
the command rmdir (remove directory) is used to remove a directory which should be empty.
To remove the file from the /tmp directory and remove the directory My_Docs, type the
following command:
rm /tmp/new
rm ~/My_Docs/*
rmdir ~/My_Docs
Week 8
Computer Systems
2. File Permissions
Access control on a Linux system mirrors that of a UNIX system with each file and directory
assigned access rights for:
1. The owner of the file/directory
2. The group to whom the file/directory belongs
3. Everybody else
For each of these, there are three possible permissions:
1. Read
2. Write
3. Execute
If you combine these, you get 9 flags that can be set. if you view a directory using the long
listing format flag, you can see this information. For example, using the following commands,
you can get the list of files that are in the /boot directory along with their permissions. Here,
we only show some file with different permissions.
cd boot
ls -l
To change the default permissions, there are two ways to use chmod command. The first is to
assign the permissions as binary octet for a class:
1. The first digit describes the owner permissions (convert to binary!) as 111 which
assigns rwx
2. The second digit describes the group permissions as 101 or r-x
3. The third digit describes the permissions for all other users, in this case 000 or --- The
alternative is to describe the change you want to make.
chmod 750 myfile1.txt
The second is to use symbols for a class and the assigned permission as follows:
1. The first character is the class (u=use/owner, g=group, o=others, a=all)
2. The second character is the operator (+ means add and - means remove)
3. The third character is the mode affected (r=read, w=write, x=execute)
chmod a+x myfile1.txt
Note: This is just an example a file. Create another file and change its permissions as you
wish.
Week 8
Computer Systems
to type :wq while to exit the vi editor without saving the changes, you have to type :q!. To create
a new file myfile.txt and edit its content as shown in the figure bellow, type the following
command:
vi myfile2.txt
The command cat can be used to display the contents of a file on the screen. To display the
contents of myfile2.txt file, type the following command (see figure below)
cat myfile2.txt
The command grep is used to search a given file for lines containing a match to the given strings
or words. To search for the lines that contains the word first in the file myfile2.txt, type the
following command (see figure below)
grep first myfile2.txt
4. Pipes
You may have noticed that there are a lot of files in
the /bin directory, including many of the most
common commands you will be using. What if you
want to search for a particular file?
It is the time to learn about Linux pipes. A pipe
(indicated by the | character) allows Linux to send
the output of one command to another command
for processing. For example, when you run the ls
command, its output is sent to the screen stdout
(which is the default).
So, if you want to display the files that only contain
“ls” (letter “l” followed by letter “s”). We can pipe
the output of ls command to list only the programs
that includes “ls” in their names. Typing the
command ls | grep ls in the /bin directory, you
should get the following outcome (or similar).
Week 8