0% found this document useful (0 votes)
58 views59 pages

Slides

The document provides an introduction to Linux, explaining that Linux is a kernel and not a complete operating system by itself. It discusses the components of an operating system, the concept of Linux distributions, and the benefits of using Linux, such as customization and respect for user privacy. Additionally, it covers basic shell commands, software management through package managers, and debugging techniques for programming in a Linux environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views59 pages

Slides

The document provides an introduction to Linux, explaining that Linux is a kernel and not a complete operating system by itself. It discusses the components of an operating system, the concept of Linux distributions, and the benefits of using Linux, such as customization and respect for user privacy. Additionally, it covers basic shell commands, software management through package managers, and debugging techniques for programming in a Linux environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Linux

Nobody actually creates perfect code the first time around,


except me.
Source – Linus Torvalds, creator of Linux

Operating Systems Downloading Gang


Open Source Developers Group
What is an operating system?
A computer can be roughly divided into four components:
the hardware, the operating systems, and application programs.

CPU, GPU, Keyboard, Monitor Linux! Firefox, Terminal, File Manager

Introduction to Linux
What is an operating system?
But is Linux really an Operating System?
Linux on its own is a “Kernel”, a piece of software that is responsible for
(among other things) bridging hardware and software together.
For example, when an application wants to read a file from the disk, it
reaches out to the Kernel, which in turn knows how the disk works,
ensures that the application (and the user) have permission to access
that file, and returns the file back to the application.
Kernels are not unique to Linux; Windows has the NT kernel for example.

Introduction to Linux
What is an operating system?
What else makes an operating system?
The kernel isn’t the only piece of software included in the OS.
Can you name a few others?
• Bootloader – Responsible for booting the OS.
• Login Manager – The username/password screen you see.
• Desktop Environment – The GUI you interact with in your OS.
• Package Manager – For installing other software.
• Command line utilities …and much more!

Introduction to Linux
What is an operating system?
Who provides the other software?
Since Linux is just the Kernel, who provides the other software?
In Windows, Microsoft makes all the other software as well. If you do
not like how windows looks, or what (core) utilities are included, it is
very hard to replace/remove them (Microsoft Edge, anyone?)
But in Linux, you can choose whatever other software you want to
install along with the Kernel. A suite of software is made by the GNU
team. They make other OS utilities and use Linux as the Kernel.
But it gets cumbersome to install everything on your own…
Introduction to Linux
Linux Distributions
Enter Linux Distributions! Distributions, or “Distros”, are a collection of OS
utilities along with the Linux Kernel that will make up an entire operating system.
Since there are so many different choices for software, some groups have chosen a
wise collection and “packaged” them into Distributions. If you don’t like their
choices, you can just pick another distro, or make your own!
Some examples of distros are Fedora, Ubuntu, Linux Mint, Nobara, etc.
Distros can also be derived from other distros! This means that if you don’t like
some included software, but like the rest, you can fork the distro, change out the
software, while keeping the rest! The beauty of open-source!

Introduction to Linux
Linux Distributions
What software is included?

Ubuntu Fedora KDE Arch Linux


Bootloader GNU gRUB GNU gRUB bring your own
Init System systemd systemd systemd
Package Manager apt dnf pacman
Login Manager GDM SDDM bring your own
DE GNOME KDE bring your own
Firefox, Nautilus, Firefox, Dolphin,
User Applications bring your own
Papers, Loupe Okular, Gwenview

Unlike Windows, you can remove any software that is installed by default, including the boot loader!

Introduction to Linux
Linux Distributions

https://youtu.be/55MwAlcpvK4

Introduction to Linux
Why Linux?
why did we make you install this?
For your course work
Most (compulsory) courses that you’ll take, like any programming
course (C Programming, ISS, CSO, OSN, DAA, etc) will be much easier
to do on Linux, and in some cases (CSO/OSN), require Linux.
Even for other courses, some software for Linux are better built and
easier to use as compared to alternatives available on other OSes.

Introduction to Linux
Linux respects you.
Linux distros are made by people who respect their computers and want
it to do what you want, not what a company’s shareholders want.
Think about the sheer number of controversies that Microsoft has
gotten into:
• ads in the start menu
• the privacy nightmare that is Recall
• “Copilot” being thrown everywhere
• Windows Update running when you’re in the middle of important
work
Introduction to Linux
Linux respects you.
• Massive amounts of telemetry being • Very limited customization
sent • More resource usage
• Cannot use your computer (easily) • https://en.wikipedia.org/wiki/
without a microsoft account Criticism_of_Microsoft#Privacy_
• Files get saved to OneDrive by issues
default • Costs Money
• Microsoft keeps advertising their • Not POSIX compliant
services to you • Windows Store
• Preinstalled bloatware that cannot be • Higher disk usage
removed • Not Open Source
• Subpar software
Introduction to Linux
Customization!
You can make Linux look like however you like!
On Windows and Mac, most people’s computers look the same :(
On Linux, you can customize it to no end!
There are some desktop environments that exist on Linux

Figure 1: GNOME Figure 2: KDE Figure 3: Cinnamon


Introduction to Linux
Customization!
But there are also these things called Window Managers!
They are minimal software that manage just your open windows, and do (almost) nothing else,
allowing you to customize to no degree!
Let’s take a look at some Linux desktops customized, or “riced” by some of your seniors!

Introduction to Linux
Introduction to Linux
Introduction to Linux
Introduction to Linux
Questions?
Checkpoint!
How many of you have followed the after-install steps?
IIIT WiFi / VPN

Introduction to Linux
Updating your System

Figure 4: The Discover Store

Introduction to Linux
RPM Fusion
1. https://rpmfusion.org/Configuration
2. Download the free & non-free repos for Fedora 42
3. Click the first downloaded file, let it open in Discover
4. Click the install button in the top right
5. Repeat for the other file

Introduction to Linux
The Shell
A shell is a program that takes commands from the keyboard and gives
them to the operating system to perform.
It’s the fundamental way that you interact with the Linux operating
system. In the past, it was the only way to interact with a computer!
There are many different shells, each with their own features, but the
most common one is called Bash (Bourne-Again Shell).
Other shells include Zsh, Fish, and Dash.

Introduction to Linux
The Terminal
So how do you use a shell? Through a terminal emulator, or
“terminal” for short.
A terminal is a program that opens a window and lets you interact with
the shell.
You’ll find the terminal in your application launcher. On Fedora KDE,
it’s called “Konsole”. On Ubuntu, it’s called “Terminal”.

Introduction to Linux
Basic Shell Commands
Navigating the Filesystem
The filesystem is like a tree, with the root directory / at the very top.
Everything on your computer is located somewhere in this tree.
Here are some commands to help you move around:

ls List - shows you the files and directories in your current location
cd Change Directory - lets you move to a different directory
pwd Print Working Directory - shows you where you are right now

Introduction to Linux
Basic Shell Commands
For example, to move to the /etc directory and see what’s inside, you
would type:
cd /etc
ls

Introduction to Linux
Basic Shell Commands
Creating and Deleting Files and Directories
mkdir Make Directory - creates a new directory
touch creates a new, empty file
rm Remove - deletes a file
rm -r Remove Recursively - deletes a directory and everything
inside it. Use with caution!
rmdir Remove an empty directory

Introduction to Linux
Basic Shell Commands
Let’s create a directory called projects, and inside it, a file called
script.sh:

cd /tmp
mkdir projects
cd projects
touch script.sh

And now let’s delete it.


cd ..
rm -rf projects
Introduction to Linux
Basic Shell Commands
Copying and Moving Files
cp Copies a file
cp -r Copies a folder recursively
mv Moves a file

Introduction to Linux
Basic Shell Commands
Getting Help
If you’re ever unsure about what a command does, you can use the man
command to read its manual page. For example, to learn more about the
ls command, you would type:

man ls

You can use the arrow keys to scroll up and down, and press q to quit.

Introduction to Linux
Basic Shell Commands
Most commands have a --help flag that prints a short summary of what
the command does and the options it accepts.
mkdir --help

Introduction to Linux
Basic Shell Commands
Viewing Files from the Terminal
You’ve created files, but how do you see what’s inside them without
opening a graphical application?

cat Prints out the entire file contents


less Lets you scroll through the file
head/tail Show the first/last 10 lines of a file
wc Get the word/character/line count of a file

Introduction to Linux
Basic Shell Commands
Editing Files in the Terminal
For editing configuration files or writing simple scripts, you don’t need
to leave the terminal.
You could use a terminal text editor like vim, neovim, helix, etc.
Fedora comes with the nano editor pre-installed. nano is a simple
terminal text editor that lets you edit files from your terminal itself!

Introduction to Linux
Basic Shell Commands
Let’s create a file using nano. Run the command
nano ilovelinux.c

And write the below text in it:


#include <stdio.h>

int main() {
printf("I love Linux!\n");
return 0;
}

Introduction to Linux
Basic Shell Commands
To save the file, press Ctrl-S. Then, press Ctrl-X to exit.

Introduction to Linux
Piping
One of the most powerful features of the Linux shell is the ability to
chain commands together using the “pipe” | character.
The pipe takes the output of the command on its left and uses it as the
input for the command on its right.
history | less

Introduction to Linux
grep

Searches for a specific pattern of text. Extremely useful with pipes.


cat .bash_history| grep cd

The grep command offers a rich set of flags and options that allow us to
perform a wide variety of searching and filtering tasks.
How can you learn all of them?
RTFM.
man grep

Introduction to Linux
Compiling Code
How do you turn your source code into a runnable program? You use a
compiler!
The most common compiler for C on Linux is gcc.
To compile a simple C file named ilovelinux.c, you use the following
command:
gcc ilovelinux.c -o ilovelinux

Introduction to Linux
Compiling Code
gcc ilovelinux.c -o ilovelinux

gcc The compiler program


ilovelinux.c The source file
-o Lets the user specify the executable name
ilovelinux The resulting executable

You can then run the executable like so:


./ilovelinux

Introduction to Linux
Debugging
How do you debug your segmentation faults? You use asan and gdb!
First, install asan and gdb:
sudo dnf install libasan libubsan gdb

This is required on Fedora but not Ubuntu.


You can find the cheat sheet for using gdb here: https://cheat.sh/gdb.

Introduction to Linux
Debugging
Let’s write some code that will cause a segmentation fault:
int main() {
int index = 1 << 31;

int array[42];
array[index] = 13;

return 0;
}

Introduction to Linux
Debugging
Compile and run the program. You will notice that the program
terminates with a SIGSEGV signal. Does anyone know where the error
is?
The index of the array being written to is too large – we declared the
array with a size of 42, but we are trying to write to the 2147483648th
index.

Introduction to Linux
Debugging
How do we find this using gdb?
# compile with the `-g` flag
cc segfault.c -o segfault -g
gdb ./segfault

Run the program in gdb:


run

Introduction to Linux
Debugging
It will show you the line where the segmentation fault occurred:
Starting program: ./segfault

Program received signal SIGSEGV, Segmentation fault.


0x0000000100001165 in segfault () at segfault.c:5
5 array[index] = 13;

Easy, right?

Introduction to Linux
Debugging
Address Sanitizer (asan)
You can compile your program with this library. It checks for invalid
memory access issues and tells you where that happened.
cc segfault.c -o segfault -fsanitize=address -g
./segfault

Now, run the program with ./segfault, and see that asan tells you
what line number causes the issue (and the type of issue – use after free,
out of bounds, etc as well).

Introduction to Linux
Undefined Behaviour Sanitizer (ubsan)
If you’ve heard of undefined behaviour, you’ll know that good C
programs must avoid it. Unfortunately, not all UB is easy to catch.
This is where ubsan comes in. Write this code in ub.c, it has some
undefined behaviour:

Introduction to Linux
Debugging
#include <stdio.h>
#include <limits.h>

int main() {
int a = INT_MAX;
int b = a + 1;
printf("%d\n", b);

return 0;
}

Introduction to Linux
Debugging
Compile and run the code.
cc ub.c -o ub -fsanitize=undefined -g
./ub

It should produce the following output:


ub.c:6:7: runtime error: signed integer overflow: 2147483647
+ 1 cannot be represented in type 'int'
-2147483648

Introduction to Linux
Debugging
This tells us that on line 6, we are adding 1 to int’s maximum
representable value, which is undefined behavior.

Introduction to Linux
Let’s compile a program
1. Download https://osdg.iiit.ac.in/files/compile-this.tar.gz
2. Extract this file
3. Compile the program
4. Run the program

Introduction to Linux
Software Management
The Package Manager
How do you install software on Linux? Unlike a certain other operating
system, you don’t go hunting for .exe files on sketchy websites. Instead,
you use a package manager.
A package manager is a tool that handles finding, installing, updating,
and removing software from trusted online sources called repositories.
On Fedora, our package manager is called dnf.

Introduction to Linux
Software Management
Here are some essential dnf commands. Since installing and removing software
affects the whole system, you need to tell the computer you have administrative
rights by using sudo.

Search for a package dnf search <query>


Install a package sudo dnf install <package-name>
Remove a package sudo dnf remove <package-name>
Update all packages sudo dnf update

Introduction to Linux
Software Management
If you’re on Ubuntu / Linux Mint, use the apt package manager instead.

Search for a package apt search <query>


Install a package sudo apt install <package-name>
Remove a package sudo apt purge <package-name>
Update all packages sudo apt update && sudo apt upgrade

Introduction to Linux
Software Management
For example, to install the cmatrix command, you would run:
# On Fedora
sudo dnf install cmatrix

# On Ubuntu
sudo apt install cmatrix

The system will ask for your password, and then dnf will ask for your
confirmation.

Introduction to Linux
Flatpaks
Flatpaks are another way to install packages on your system. dnf and
apt are usually used for CLI tools, and flatpak is usually used for GUI
tools.
Flatpaks have non-opensource apps like Chrome and Discord that you
can install. Flatpaks are sandboxed.
Flatpaks come from a place called Flathub.

Introduction to Linux
Software Management

Introduction to Linux
Software Management
Ubuntu/Linux Mint users – You have snap instead of flatpak.
Your applications come from SnapCraft, not Flathub, and your
commands are snap, not flatpak.
You could install flatpak on Ubuntu by following the steps here, but
there’s no reason to.

Introduction to Linux
Software Management
Set up flathub with the following command:
flatpak remote-add --if-not-exists flathub https://dl.
flathub.org/repo/flathub.flatpakrepo

And remove the default fedora repo (since that has no closed-source
apps).
flatpak remote-delete fedora

And now you can install apps like Chrome or Discord from Discover, or
by using the flatpak install command.
Introduction to Linux
What is Open Source?

You might also like