Categories
Linux Tutorial Series

Linux Tutorial Series – 12 – What is a shell?

Here is the video version, if you prefer it:

The shell, the shell… We all heard that. We know you can type some command in the shell in a Linux environment and get some output. But what does the shell actually mean?

“A shell is a program that runs commands”, says (Ward, 2014)⁠. That is basically it. You type some commands in, the shell executes them, then you get some output. Shell scripts, another popular term, are essentially just commands typed in a file called a shell script; so the shell has the same job – execute commands.

There are multiple kinds of shells. You can find more information here: (“5 Most Frequently Used Open Source Shells for Linux,” n.d.)

Before I end, it is important to note that programs like Terminal are not actually shells – they are graphical user interfaces running shell on your behalf. (Barrett, 2016)⁠ Figure 1 depicts this. This program with a graphical user interface, called a terminal emulator, interacts with the shell. (Shotts, 2019)⁠

Figure 1 – Relationship between graphical user interfaces to the shell and the shell itself (modeled after figure on page 15 of (Barrett, 2016)⁠)

Hope you learned something new!

References

5 Most Frequently Used Open Source Shells for Linux. (n.d.). Retrieved December 22, 2019, from https://www.tecmint.com/different-types-of-linux-shells/

Barrett, D. J. (2016). Linux pocket guide (3rd ed.). O’Reilly Media. Page 15

Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Page 26

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Page 12

Categories
Linux Tutorial Series

Linux Tutorial Series – 11 – Checkpoint

Here is the video version, if you prefer it:

In the following section of the posts, we will talk about some really foundational things, such as what is a shell, what is a command, what are absolute and what are relative paths and so on.

All of the conceptual things covered here will be of crucial importance later on, so it pays to pay attention.

Talk soon!

Categories
Linux Tutorial Series

Linux Tutorial Series – 10 – Recap

Here is the video version, if you prefer it:

We have talked about what an operating system is – it is a very useful piece of software which enables you to communicate with the hardware conveniently. We also talked about the kernel and learned that it manages processes, memory, device drivers and system calls, as well as established that users are people that use the computer and each one has (or should have) a user account associated with him/her.

We established that there is a difference between the user space and the kernel space, as well as there being a difference between regular users and superusers. Kernel space is only accessible to the operating system, while the user space is where the user programs reside. Superusers get to execute certain commands that regular users can’t (don’t have the permission to). We learned that a Linux distribution is an operating system made from a software collection that is based upon the Linux kernel.We also talked about some Linux installation details.

Hope this served as a good review!

Categories
Linux Tutorial Series

Linux Tutorial Series – 9 – Installing Linux

Here is the video version, if you prefer it:

In this article, I will explain how to install Linux on your machine. I will assume you are installing Debian (Debian 9 to be specific), but most likely any Linux distribution will have a similar installation process. If not, there is a website called Google, through which you can find guides that guide you through the specifics of your installation.

When I installed Debian on my PC, I pretty much just clicked “Next” all the time. I used the default settings. Nothing fancy. The only setting up I had to do was when I was creating my partitions. Partitions are subdivisions of your hard disk drive or your solid state drive. Partitions enable you, so to speak, divide up your disk into different compartments. We will talk more about this later on, but a guide I used for this (and you can use for this) is (Trivedi, n.d.).

There is also one thing I was uncertain about, which is swap. Swap is a part of your hard disk drive (and when I say hard disk drive, I mean solid state drive as well, if you have one) that you can use if you run out of Random Access Memory (RAM). So for example, if I have 8 Gigabytes (GB) of RAM⁠, and if I need 9 GB to run all my processes (since all processes reside in RAM) I need 1 additional GB of RAM. That additional 1 GB gets taken from the swap space. Swap space is also used when you hibernate your computer. (“SwapFaq,” n.d.)⁠ I found a really good guideline for swap space here – (“I have 16GB RAM. Do I need 32GB swap?,” n.d.). The second answer from the top contains a nice table. There are other guides on this website called Google, feel free to use them, but in general I think that if your swap is at least the size of your RAM, that’s going to be fine.

A note: You can also install Linux on a virtual machine and learn how to use Linux via a virtual machine, or maybe you can have a dual boot with both Windows and Linux and slowly switch over to Linux. I personally found those approaches to be less effective. The reason was that I would keep using Windows over Linux, even though I knew I should use Linux. Maybe for you this will work, so I am mentioning it here.

A Google search for “How to set up Linux on VirtualBox” (VirtualBox is used for virtualization) can help you set that up.

Hope this helped!

References

I have 16GB RAM. Do I need 32GB swap? (n.d.). Retrieved December 22, 2019, from https://askubuntu.com/questions/49109/i-have-16gb-ram-do-i-need-32gb-swap

SwapFaq. (n.d.). Retrieved December 22, 2019, from https://help.ubuntu.com/community/SwapFaq

Trivedi, Y. (n.d.). How to Choose a Partition Scheme for Your Linux PC. Retrieved December 22, 2019, from https://www.howtogeek.com/howto/35676/how-to-choose-a-partition-scheme-for-your-linux-pc/

Categories
Linux Tutorial Series

Linux Tutorial Series – 8 – Linux distribution

Here is the video version, if you prefer it:

I wanted to clarify a term, which is Linux distribution. Linux distribution is an operating system made from a software collection that is based upon the Linux kernel. (“Linux distribution,” n.d.)

What does that mean? That means that all Linux distributions have the same kernel (which, as we discussed, is the central part of the Linux operating system)⁠, but they differ in the software which comes supplied with them.

Which Linux distribution should you pick? I can only recommend what I used so far – either Ubuntu or Debian. There are a lot of others, so feel free to pick the one you like. I prefer Debian over Ubuntu, but again, feel free to pick the one you like.

Hope you learned something useful!

References

Linux distribution. (n.d.). Retrieved February 29, 2020, from https://en.wikipedia.org/wiki/Linux_distribution

Categories
Linux Tutorial Series

Linux Tutorial Series – 7 – Superuser and a regular user – what is the difference?

Here is the video version, if you prefer it:

What is the difference between the superuser and the regular user? The superuser (also known as root) has some extra privileges on the Linux system. (Ward, 2014)⁠ For example, if you are a regular user and you try to modify some system files, you will most likely not be able to save them and get “Permission denied” error. That’s because system files are only accessible by the superuser.

So the superuser is the most powerful user on the Linux system. Other users aren’t as powerful (meaning they can’t modify some files and can’t execute some commands). But guess what – that is good. “How can that be good?”, you might wonder. Well, imagine you downloaded a malicious piece of software that tried to modify your system files and you are logged in as a regular user. When the malicious piece of software tries to modify some system files, it can’t, because a regular user can’t modify them, you are running the program as a regular user and thus the malicious program can’t modify the files. I am not an expert in information security, but I remember this example being tossed around in some of my college classes, so I decided to put this in.

Hope this helped clarify the difference between the superuser and other users.

References

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 9-10

Categories
Linux Tutorial Series

Linux Tutorial Series – 6 – User space and system space – what is the difference?

Here is the video version, if you prefer it:

User space is the space that “normal” processes use. System space (aka kernel space) is the space that only the operating system can use.

See, every program has to be stored in random access memory (RAM). That means that the operating system also has to be stored in RAM. (Ward, 2014)⁠ So the operating system uses the RAM, user programs (your normal every day programs such as Mozilla Firefox) use the RAM, everyone uses the RAM! Now, the thing about the operating system is, because of security reasons and because of potential issues, it limits the user processes to a part of RAM called user space and the operating system resides in a different part of the RAM. If any process (process being another word for a program you have started on your computer) tries to access any part of the memory which is not its own, it can’t. The operating system makes sure of it. The figure below should help clarify things.

Figure 1 – System and user space (my own illustration)

Hope you learned something useful!

References

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 8-9

Categories
Linux Tutorial Series

Linux Tutorial Series – 5 – Users

Here is the video version, if you prefer it:

This quick post serves one purpose – to tell you that users are the people who use the computer. More specifically, every user has (or at least should have) a user account associated with him/her. That means that multiple people can use the computer and it is desirable that each one of them has their own user account, because Linux makes sure that users can’t access each others stuff.

Thank you for reading!

Categories
Linux Tutorial Series

Linux Tutorial Series – 4 – Zooming in on the kernel – what are its responsibilities?

Here is the video version, if you prefer it:

As described on page 4 in (Ward, 2014)⁠, the kernel, which is the core of the operating system, deals with the following four things:

  • Processes
  • Memory
  • Device drivers
  • System calls

Let’s look at each one in turn.

Proccesses

The kernel starts, pauses, resumes and terminates processes. The kernel is also responsible for giving processes the hardware they need to execute the thing they were programmed to do. That’s why we need hardware – we need hardware to actually perform the calculation the programmer intended it to do. The kernel decides which process gets what hardware at what time, as there are multiple processes running at the same time on the computer. For example, you most likely have a web browser open, as well as a File Explorer, as well as something else.

Memory

The kernel makes sure to:

  • give memory to a process
  • check if the process is only accessing its own memory and not some other processes memory
  • clean up the memory after the process terminates

When I say memory here, I mean RAM, that is, random access memory. Think of RAM as storage space – every program is stored in RAM as it is executed. The kernel makes sure to give each process enough RAM and to free up the RAM when the process terminates so other programs can “step in” the newly vacant storage space.

Why is it important for the process not to access other processes memory? Well, if it writes to some other processes memory, it could overwrite some data which may be really important for that process, which would be bad. There are other reasons, but since I am not a professional at information security at this point, I feel unqualified to talk about it.

Device drivers

The kernel manages the device drivers. Remember those things you have to install every time you install a new Windows on a computer that enable you to use some hardware (i.e. your speakers)? Well, two things about that. Number one, you (in most cases) don’t have to install drivers on Linux as they come preinstalled, so switch to Linux (subtle nudge into the Linux world, eh?). Number two, device drivers make it easy for programmers to talk to the hardware.

How is that? Let’s say I wanted to write some files to a hard disk. If I had a Samsung hard disk drive (HDD), and you had Seagate, the code for writing to Samsung HDD vs writing to Seagate HDD would most likely be different since they would have different hardware responsible for the task of writing to the HDD. Operating system allows me not worry about the details of the hardware. So instead of saying to the operating system “Write this to Samsung HDD” or “Write this to Seagate HDD” I just say “Write this to the HDD”. The operating system takes care of the specifics of the hardware.

System calls

System calls “call” the kernel to do something for them. For example, from my program (which is, let’s say, Firefox), I first tell the operating system to “write something to the HDD”. Then, the kernel takes over and writes it to the HDD for me and gives me some feedback on how did it go. Was it successful? Was it a failure? If it failed, why? Those are some things that the operating system handles for me.

In addition to this explanation, there are some terms frequently used when talking about process management. I list those in the References with relevant links if you are interested. Those are:

  • (“Timeslicing,” n.d.)⁠
  • (“Context switch,” n.d.)⁠

Hope this was useful!

References

Context switch. (n.d.). Retrieved April 7, 2020, from https://en.wikipedia.org/wiki/Context_switch

Timeslicing. (n.d.). Retrieved April 7, 2020, from https://en.wikipedia.org/wiki/Timeslicing

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 4-8

Categories
Linux Tutorial Series

Linux Tutorial Series – 3 – What is an operating system and why do we need it?

Here is the video version, if you prefer it:

Wikipedia defines operating system as “system software that manages computer hardware, software resources, and provides common services for computer programs”. (“Operating system,” n.d.) In simpler language, operating system is the “glue” which enables applications such as Mozilla Firefox (from here on just Firefox) to communicate with your computer hardware.

Why would Firefox, or Microsoft Word, or any program, for that matter, have to communicate with your hardware? Well, let’s take the example of Firefox. Firefox has to somehow display the web page you request. How does it do that? Well, there are two solutions to this issue. The first one is believing in magic and just saying “It’s magic.”. But this post should help take some magic away.

Think of it like this – Firefox (a user process) exists on a certain “level” of your computer, as depicted in Figure 1.

Figure 1 – Operating system “levels” (modeled after Figure 1 on page 3 of (Ward, 2014))⁠⁠

In order to communicate with other “levels” of your computer, Firefox has to call certain operating system functions. So metaphorically it knocks on the operating systems door and asks – “Hey operating system, fetch me the data I just received in the network card, will ya?”. “Why wouldn’t Firefox access your network card directly?”, you may ask.A fair question. Two reasons:

  • It would be very difficult to program software that way; every software developer would have to deal with low-level hardware and that would be tedious. Also, imagine if someone wrote some code to deal with a certain piece of hardware and then someone else had to write it all over again for their program – that would mean every programmer has to start from scratch (literally) every time he writes some code
  • Imagine you are running two applications (let’s call them Firefox and Firefox2) and that both are trying to send some data over the network concurrently – uh oh. The data sent from Firefox and Firefox2 could mix together, creating some data that doesn’t resemble anything Firefox or Firefox2 tried to send.

This is why you call the operating system functions to interact with the hardware. They take care of the nitty-gritty details of communicating with hardware and make sure that there are no things such as two applications overwriting each others contents.

Put another way, operating systems are a layer of abstraction that eases programming in the upper layers of abstraction and makes programmers life more simple. They are the thing we take for granted today, but they are very, very, very challenging to make (program). Writing an operating system is super hard. I have never done it, but I imagine it is very difficult, since I have wrote some lower-level software and that was hard. So thank you operating systems (and operating system software engineers) for making our life easier. Hopefully after this post we will appreciate you more.

References

Operating system. (n.d.). Retrieved December 21, 2019, from https://en.wikipedia.org/wiki/Operating_system

Ward, B. (2014). How Linux Works: What Every Superuser Should Know (2nd ed.). No Starch Press. Pages 1-3