01. Lab - Introduction to Computer Organization (1)
01. Lab - Introduction to Computer Organization (1)
2
Hardware - Software
01. Click on this link. This will open the website where you can download the installer
file for Oracle VM VirtualBox, depending on your operating system. In this
document, we will use Windows.
02. After opening the link, under “VirtualBox 7.0.14 platform packages”, select
Windows hosts. This will download the installer file.
3
03. After the download process is done, run the .exe file.
04. The best approach is to install the VirtualBox with default settings, so we can
proceed the installation process by selecting the “Next” option.
4
05. You will also be prompted to install the necessary network drivers for VirtualBox.
Select “Yes”.
5
07. When the installation process is finished, select the “Finish” option which should
open the VirtualBox in a matter of seconds.
6
Downloading and setting up Ubuntu with VirtualBox
01. Click on this link. After a few seconds, you will start downloading the .iso file for
Ubuntu 22.04.4 LTS.
7
02. Open VirtualBox and select the “New” option
03. This will open a new window where you need to specify the name of your virtual
machine as well as the ISO image (here, you should import the downloaded .iso
file). Select the arrow and click on “Other”.
8
05. Select “Next” where we will now deal with configuring the user profile.
9
The default username is vboxuser while the password is changeme. The best
approach is to change these credentials because the default vboxuser profile will
not have sudo access. Also, you can select the “Guest Additions” checkbox which
will install all additional drivers and tools after the Ubuntu installation process is
finished (not mandatory). Select “Next”.
06. Now it is time to assign resources from our PC to the virtual machine. In
accordance with the official documentation of Ubuntu, the best amount of
resources for a virtual machine is 8 GB of RAM and 4 CPUs. However, the most
10
important part is to keep the sliders in the green area. We will assign 4 GB of RAM
and 2 CPUs. Select “Next”.
07. At this stage, we should now specify the virtual hard disk size. We can leave it as
default to be 25 GB. Select “Next”.
11
08. We will be redirected to the Summary window where we will see all information
about our virtual machine specification. Select “Finish”. This will also launch the
virtual machine and the installation process. Now you should just wait for the
process to finish.
12
09. After the installation process is finished, the virtual machine will reboot itself and
will lead us to the login screen. Enter the user profile password which you specified
at the installation beginning. This will open the introductory screen where you may
enter your e-mail address and specify the basic settings.
13
10. After finishing the introductory screen, your Ubuntu is ready for use.
14
Terminal Basics
When you access the terminal (CTRL + ALT + T), you can see the command prompt waiting
for you to enter the Unix command:
zehra@zehra-VirtualBox:~$ i
If at any point you are in a terminal window and don't have a command prompt, but want
or need one, type Control-C to interrupt the currently executing command and get a fresh
command prompt. An example where you might want this is if you executed a program
that contains an infinite loop - since you normally don't get a new terminal prompt until
15
the previous command has finished executing, you can use Control-C to terminate
whatever is running and get back to the shell.
Command Form
where the program is the name of a program you are executing; various sets that affect
program behavior are represented by options; and argument(s) is(are) piece(s) of data
handed to the program. Of course, not all commands follow this form.
Note: we could use just ls as a command, and in that case, we would get a list of files from
the working directory (without hidden files); also we could just type ls -a and get all files
(including the hidden) from the working directory. In the same manner, we could avoid the
options part of the command.
Help
Due to the number of different commands and command-line options for many
commands, it can be hard to keep track of them all! Luckily, there is a handy built-in
manual that contains detailed information on how to use every individual command. To
view the manual on a particular command (which most notably, describes all the command
line flags that a command accepts), use the man command.
You can also use the command whatis, which will output only one line description of the
command.
Example:
zehratheuser@zehratheuser:~$ whatis ls
16
ls(1) - list directory contents
When you are not sure of the exact name of a command, you can use apropos command,
and pass a keyword as an argument to that program. It will output the list of commands
corresponding to the keyword (Figure 2.).
Figure 2. Apropos
Know thyself
At any given point your terminal session "exists" within a specified directory, called the
working directory. The output of many commands depends on your working directory. You
can locate yourself (find out which is your current working directory) with command pwd
(Print Working Directory). You can use the whoami command to find out as which user
you are currently logged in. And with passwd you can change your password (Figure 1).
17
Figure 3. Know Thyself
A relative path, on the other hand, does not start with a forward slash, and refers to a
pathname relative to the current working directory.
Example: If I am currently located in /home and I try to change the current directory to
zehra (NOT /home/zehra), then I am saying I want to go to the directory named zehra,
located within the current working directory.
Obviously, the file indicated by a relative path depends on the current working directory.
In contrast, an absolute path does not depend on the current directory. In most cases,
relative pathnames are used, as they usually involve less typing.
One special and important case of relative pathnames is the special directories 'dot' (.) and
'dot dot' (..). The . directory refers to the current working directory, while the .. directory
refers to the parent directory of the current working directory.
Example: If you are located in your home directory (/home/zehratheuser), with the
following command you can move to parent directory (/home):
zehratheuser@zehratheuser:~$ cd ..
18
zehratheuser@zehratheuser:/home$ cd ..
The command cd (Change Directory) is used to change the current working directory. It
can be used with an absolute or relative path, or even without arguments (changes the
current working directory to your home directory no matter where you currently are).
File manipulations
To create (or edit) files via the command line, we use a command-line text editor. This is an
editor that has its entire interface within a terminal window. There are many
command-line text editors that have various pros and cons. The two most well-known
command-line editors are Vim and Emacs, but we will use Nano. To start editing a new file
using Nano, simply call the nano command with the desired filename of the new file to
create.
You are now in the nano interface and can type just as you would in any other editor. Some
commands are shown along the bottom of the window -- note that the caret symbol (^) refers
to the control key. The most important commands in nano are ^O to save the file and ^X to
quit nano. Nano includes many other commands for things like cutting/pasting text and
searching through the file. A cheat sheet of Nano commands is here.
Type some text in your new document, then save and quit the editor. Verify the contents of
your new file with the cat command.
To open the now existing file and change it, simply rerun nano myfile.txt, which will open
up the existing file in the Nano window.
19
zehratheuser@zehratheuser:~$ sudo apt install build-essential
The command installs a bunch of new packages including gcc, g++ and make.
● You may also want to install the manual pages about using GNU/Linux for
development:
zehratheuser@zehratheuser:~$ sudo apt-get install manpages-dev
● To validate that the GCC compiler is successfully installed, use the gcc --version
command which prints the GCC version:
zehratheuser@zehratheuser:~$ gcc --version
The gcc command takes a list of source files to compile (in this case, just hello.c) and
outputs the compiled executable (or a list of errors if the program does not compile). In the
above command, we are passing two flags in addition to the filename: -Wall (Warnings: all)
says to turn on all compiler warnings, and -o hello says we want the output executable file
to be named hello. If we omit the -o hello option, then gcc defaults to producing an
executable named a.out.
zehratheuser@zehratheuser:~$ ./hello
Note that the ./ indicates that we're running a program located in the current directory.
20