Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

[Linux] Add Linux part to the course contents #183

Draft
wants to merge 15 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/img/linux-distros-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53,404 changes: 53,404 additions & 0 deletions assets/img/linux-distros-tree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/linux-fs-layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-course"
version = "2023.11.dev"
version = "2024.01-dev"
description = "Python training course materials"
license = "MIT"
authors = [
Expand Down
3 changes: 3 additions & 0 deletions src/appx/busybox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
###############################################################################
BusyBox Commands
###############################################################################
1 change: 1 addition & 0 deletions src/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
appx/wtk
spec/blog/index
spec/libms/index
appx/busybox

.. rubric:: References

Expand Down
95 changes: 95 additions & 0 deletions src/linux/commands.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
*******************************************************************************
Commands
*******************************************************************************

A computer's operation, no matter which operating system it is running, can be
loosely described in three steps:

#. The computer waits for user input
#. The user selects a command and enters it via keyboard or mouse
#. The computer executes the command

In a Linux system, the shell displays a "prompt", meaning that commands can be
entered. This prompt usually consists of a user and host (computer) name, the
current directory, and a final character:

::

user@host: /home/user >

Command structure
=================

A command is essentially a sequence of characters which is ends with a press
of the **enter** key and is subsequently evaluated by the shell. Many commands
are vaguely inspired by the English language and form part of a dedicated
"command language". Commands in this language must follow certain rules,
a "syntax", for the shell to be able to interpret them.

To interpret a command line, the shell first tries to divide the line into
words. Just like in real life, words are separated by spaces. The first word
on a line is usually the actual command. All other words on the line are
parameters that explain what is wanted in more detail.

Parameters starting with a dash (``-``) are called **options**.
These are usually optional -- the details depend on the command in question.
They are "switches" that allow certain aspects of the command to be switched
on or off. If you want to pass several options to a command, they can be
accumulated behind a single dash, i.e. the options sequence ``-a -l -F``
corresponds to ``-alF``. Many programs have more options that can be
conveniently mapped to single characters or support *long options* for
readability (frequently in addition to equivalent single-character options).
Long options most often start with two dashes and cannot be accumulated:
``--foo --bar --foobar``.

Parameters with no leading dash are called **arguments**. These are often the
names of files that the command should process.

The general command structure can be displayed as follows:

:command: what to do?
:options: how to do it?
:arguments: what to do it with?

Internal and external commands
------------------------------

In shells, there are essentially two kinds of commands:

- **Internal commands**

These commands are made available by the shell itself.
The Bourne-again shell contains approximately 30 such commands,
which can be executed very quickly. Some commands (such as ``exit`` or
``cd``) alter the state of the shell itself and cannot be provided
externally.

- **External commands**

The shell does not execute these commands by itself but launches executable
files, which within the file system are found in directories like */bin* or
*/usr/bin*. As a user, you can provide your own programs, which the shell
will execute like other external commands.

What is the shell?
==================

All kinds of definitions are available, ranging from the simple comparison that
"the shell is the steering wheel of the car", to the vague definition in the
Bash manual which says that "bash is an sh-compatible command language
interpreter", or an even more obscure expression, "a shell manages the
interaction between the system and its users".

A shell can best be compared with a way of talking to the computer, a language.
Most users do know that other language, the point-and-click language of the
desktop. But in that language the computer is leading the conversation, while
the user has the passive role of picking tasks from the ones presented. It is
very difficult for a programmer to include all options and possible uses of
a command in the GUI-format. Thus, GUIs are almost always less capable than
the command or commands that form the backend.

The shell, on the other hand, is an advanced way of communicating with the
system, because it allows for two-way conversation and talking initiative.

.. todo: get most used commands from appendix:
pwd, cd, ls, mkdir, touch, more, less, head, tail
86 changes: 86 additions & 0 deletions src/linux/filesys.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
*******************************************************************************
File system and file management
*******************************************************************************

Files
=====

A simple description of the UNIX system, also applicable to Linux, is this:

"On a UNIX system, everything is a file; if something is not a file,
it is a process"

This statement is true because there are special files that are more that just
files (named pipes and sockets for instance), but to keep things simple, saying
that everything is a file is an acceptable generalization. A Linux system, just
like UNIX, makes no difference between a file and a directory, since
a directory is just a file containing names of other files. Programs, services,
texts, images, and so forth, are all files. Input and output devices, and
generally all devices, are considered to be files, according to the system.

.. rubric:: Sorts of files

:regular files:
most files are just *files*, called *regular* files; they contain normal
data, for example text files, executable files or programs, input or
output from a program and so on.

:directories:
files that are lists of other files.

:special files:
the mechanism used for input and output.
Most special files are in ``/dev``.

:links:
a system to make a file or directory visible in multiple parts of
the system's file tree.

:sockets:
a special file type, similar to TCP/IP sockets, providing inter-process
networking protected by the file system's access control.

:named pipes:
act more or less like sockets and form a way for processes to communicate
with each other, without using network socket semantic.

The ``-l`` option to ``ls`` display the file type, using the first character
of each input line:

+--------+--------------+
| Symbol | Meaning |
+========+==============+
| ``-`` | Regular file |
+--------+--------------+
| ``d`` | Directory |
+--------+--------------+
| ``l`` | Link |
+--------+--------------+
| ``c`` | Special file |
+--------+--------------+
| ``s`` | Socket |
+--------+--------------+
| ``p`` | Named pipe |
+--------+--------------+
| ``b`` | Block device |
+--------+--------------+

Linux file system layout
========================

For convenience, the Linux file system is usually thought of in a tree
structure.

.. figure:: /../assets/img/linux-fs-layout.png
:align: center

RedHat system layout

The tree of the file system starts at the trunk or *slash*, indicated by
a forward slash (``/``). This directory, containing all underlying directories
and files, is also called the *root directory* or the *root* of the file
system.

Directories that are only one level below the root directory are often preceded
by a slash, to indicate their position and prevent confusion with other
directories that could have the same name.
132 changes: 124 additions & 8 deletions src/linux/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,133 @@
:author: Serhii Horodilov
:keywords: linux, basics, index

.. todo

.. attention:: Page is under construction

.. figure:: /../assets/img/construction.svg
:figwidth: 250
:align: center

###############################################################################
Linux Basics
###############################################################################

Linux is a powerful, open-source operating system widely used in various
domains, from embedded systems to supercomputers. It is known for its
stability, security, and flexibility, making it a preferred choice for
developers, especially in server environments.

.. rubric:: What is an Operating System?

.. _os_overview:

An operating system (OS) is the primary software that manages all the hardware
and other software on a computer.
It acts as an intermediary between the physical hardware and the user
applications, providing essential services needed for the applications
to execute.

.. _os_functions:

The operating system is the fundamental suite of software on a device that
keeps everything together. It interacts with the device's hardware components,
handling everything from input devices like keyboards and mice to output
devices like displays and printers. The OS sits between the applications you
run and the hardware, using hardware drivers as an interface between them.
For instance, when an application wants to print a document, it hands off
the task to the OS. The OS then sends instructions to the printer using printer
drivers to send the correct signals. The printing application does not need
to understand the specifics of the printer or how it works.
The OS handles the details.

OS includes a variety of software components such as system services,
libraries, and :abbr:`APIs (Application Programming Interfaces)` that
developers use to write applications that run on the OS.

The OS also manages multitasking, allocating hardware resources among multiple
running programs. It controls which processes are running, distributing them
among various CPUs if you have a computer with multiple processors or cores,
allowing multiple processes to run in parallel. It also manages the system's
internal memory, allocating memory among running applications.

When we say "computers" run operating systems, we don't just mean traditional
desktop PCs and laptops. Your smartphone is a computer, as are tablets,
smart TVs, gaming consoles, smartwatches, and Wi-Fi routers. An Amazon Echo or
Google Home is a computer device running under the management of an operating
system.

Familiar desktop operating systems include Microsoft Windows, Apple MacOS,
Google's Chrome OS, and Linux. The primary operating systems for smartphones
are Apple's iOS and Google's Android.

Other devices, like a Wi-Fi router, may run "embedded operating systems".
These are specialized operating systems with fewer features than a typical
operating system, designed specifically for a single task - like operating
a Wi-Fi router, navigating, or controlling an ATM.

Operating systems also include other software, including the user interface,
which allows people to interact with the device. This could be the desktop on
a PC, the touch interface on a phone, or the voice interface on a digital
assistant.

The operating system is a large piece of software made up of many different
applications and processes. The line between what is the operating system and
what is a program can sometimes be a bit blurred.
There isn't a strict official definition of an operating system.

For instance, in Windows, the File Explorer application is an integral part of
the Windows operating system -- it even handles drawing your user interface --
and an application running on that operating system.

.. rubric:: Linux pros

- Linux is free
- Linux is portable
- Linux was made to keep on running
- Linux is secure and versatile
- Linux is scalable
- The Linux OS and most Linux applications have very short debug-times

.. rubric:: Linux cons

- There are far too many different distributions
- Linux is not very friendly and confusing for beginners

.. rubric:: Linux -- the Kernel and distributions

The core of an operating system is the kernel.

At a low level, the "kernel" is the core computer program at the base of your
operating system. This single program is one of the first things loaded when
your operating system starts. It handles memory allocation, converts software
functions into instructions for your computer's CPU, and processes input and
output from hardware devices. The kernel typically runs in an isolated area
to prevent it from being used by other software on your computer.
The kernel of an operating system is crucial, but it's just one part of
the operating system.

Strictly speaking, the name **"Linux"** only applies to the operating system
kernel, which performs the actual operating system tasks. It takes care of
elementary functions like memory and process management and hardware control.
Application programs must call upon the kernel to, e.g. access files on disk.

However, Linux is still often referred to as an operating system.

To accomplish useful work, a multitude of system and application programs,
libraries, documentation etc. is necessary. "Distributions" are nothing but
up-to-date selections of these together with special programs (usually tools
for installation and maintenance) provided by companies or other organisations,
possibly together with other services such as support, documentation, or
updates. Distributions differ mostly in the selection of software they offer,
their administration tools, extra services, and price.

.. figure:: /../assets/img/linux-distros-tree.svg
:align: center

Linux distros tree

.. figure:: /../assets/img/linux-distros-map.png
:align: center

.. toctree::
:name: linux
:caption: Contents

commands
filesys
users
ssh
symlinks
11 changes: 11 additions & 0 deletions src/linux/ssh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*******************************************************************************
(SSH) Secure Shell
*******************************************************************************

The :abbr:`SSH (Secure Shell)` Protocol is a network protocol for secure data
communication and remote command execution. It is a cryptographic network
protocol for operating network services securely over an unsecured network. Its
most notable applications are remote login and command-line execution.

SSH uses public-key cryptographic to authenticate the remote computer and allow
it to authenticate the user, if necessary.
3 changes: 3 additions & 0 deletions src/linux/symlinks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*******************************************************************************
Symlinks
*******************************************************************************
3 changes: 3 additions & 0 deletions src/linux/users.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*******************************************************************************
Users and Permissions
*******************************************************************************
26 changes: 26 additions & 0 deletions src/refs.bib
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,29 @@ @misc{medium:db-acid-cap
date = {2017.1.12},
url = {https://cinish.medium.com/database-acid-cap-isolation-levels-371b7e06a112}
}

@manual{linux-intro,
title = {Introduction to Linux. A hands on guide},
author = {Machtelt Garrels},
}

@manual{linux-tutorial,
title = {Linux Tutorial},
author = {Jon Wakelin and Liam Gretton and Gary Gilchrist and Teri Forey},
}

@manual{linux-grd1-manual,
title = {Introduction to Linux for Users and Administrators},
author = {Tobias Elsner and Anselm Lingnau},
editor = {Anselm Lingnau},
}

@misc{busybox,
title = {BusyBox - Command Help},
url = {https://busybox.net/downloads/BusyBox.html},
}

@misc{curl,
title = {command line tool and library for transferring data with URLs},
url = {https://curl.se/},
}
Loading