Introduction to Linux - 2020/2021

Lab 01

  • Introduction to the NSWI177 paper.
  • How to get Linux OS (Dual Boot, USB, Virtual).
  • Try a huge variety of desktop environments (with focus to i3).
  • Intro to GitLab web GUI.

Lab 02

  • Questions and Answers section.
  • Command-line basics.
  • Filesystem basics.
  • BASH wildcards.
  • Introduction to Vim (see also Vim na 20 min — Petr Hodač).

Lab 03

  • Questions and Answers section.
  • Simple shell scripts + executable bit.
  • Hashbang and its usage.
  • Git on command-line (must see MIT missing semester).

Lab 04

  • Questions and Answers section.
  • Talking about STDTIN, STDOUT, STDERR.
  • Pipes

Lab 05

  • Questions and Answers section.
  • Shell scripting general.
  • BASH variables expansion.
  • regex intro.
  • grep examples.
  • sed examples.

Lab 06

  • Easter holiday.

Lab 07

  • Questions and Answers section.
  • SSH basics.
  • Unix-style access rights.
  • tmux example.

Exercise for better undestanding of Linux access rights. Try to guess in advance what will and will not work.

mkdir data
cp /etc/passwd data

## Access rights with ordinary file

# Only W bit
chmod u-r data/passwd
cat data/passwd
echo 'Modification' >> data/passwd

# Only R bit
chmod u=r data/passwd
cat data/passwd
echo 'Modification' >> data/passwd
rm data/passwd

## Access rights with directory
cp /etc/passwd data

# Only WX bits
chmod u-r data
l data
cat data/passwd
echo 'Modification' >> data/passwd
cp /etc/group data

# Only X bit
chmod u-r data
l data
cat data/passwd
echo 'Modification' >> data/passwd
cp /etc/hostname data

# Only RW bits
chmod u=rw data
l data
cat data/passwd
echo 'Modification' >> data/passwd
cp /etc/resolv.conf data

Lab 08

  • Questions and Answers section.
  • Concept of root user.
  • Archiving and compression with tar.
  • Signals in Linux.
mkdir data
cp /etc/{passwd,group,hostname} data/

tar cvf archive.tar data
tar tf archive.tar
tar uf archive.tar signals.py
tar tf archive.tar

# GZip
tar cvzf archive.tar.gz data
tar c data | gzip > archive_gzip.tar.gz

# BZip2
tar cvjf archive.tar.bz2 data
tar c data | bzip2 > archive_bzip2.tar.bz2

file archive.tar
file archive.tar.gz
file archive.tar.bz2

See following explanation from quora.

SIGINT is the interrupt signal. The terminal sends it to the foreground process when the user presses <C-c>. The default behavior is to terminate the process, but it can be caught or ignored. The intention is to provide a mechanism for an orderly, graceful shutdown.

SIGQUIT is the dump core signal. The terminal sends it to the foreground process when the user presses <C-\>. The default behavior is to terminate the process and dump core, but it can be caught or ignored. The intention is to provide a mechanism for the user to abort the process. You can look at SIGINT as “user-initiated happy termination” and SIGQUIT as “user-initiated unhappy termination.”

SIGTERM is the termination signal. The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, gracefully or not, but to first allow it a chance to cleanup.

SIGKILL is the kill signal. The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot cleanup, and thus this is a signal of last resort.

SIGSTOP is the pause signal. The only behavior is to pause the process; the signal cannot be caught or ignored. The shell uses pausing (and its counterpart, resuming via SIGCONT) to implement job control.

Lab 09

  • Questions and Answers section.
  • Details about 07/find_complementary.sh solution.
  • Details about 06/machine_status.sh -> show mem_usage.sh.
  • Python venv and why it is to use it everywhere.
  • poetry introduction.

See mem_usage.sh and export.qstat.

Lab 10

  • Questions and Answers section.
  • git live examples.
  • Some notes about git rebase and git rebase -i.

Tip: try git log --oneline --graph --all --decorate

# General shopping list
git init
cat > shopping_list.txt <<EOF
[general]
apples
bananas
1x bread
1x chocolate
EOF
git add shopping_list.txt
git commit -m 'Initial commit'

# Alice shopping list
git checkout -b alice
cat >> shopping_list.txt <<EOF

[alice]
1x nutella
EOF
git add shopping_list.txt
git commit -m 'I want Nutella'

git checkout master

# Bob shopping list
git checkout -b bob
cat >> shopping_list.txt <<EOF

[bob]
1x beef steak
EOF
git add shopping_list.txt
git commit -m 'I want steak'

# Merge
git checkout master
git merge alice
git merge bob  # Merge conflict -> vimdiff

# Cleaning branches
git branch -d alice bob

# Cenek shopping list
git checkout -b cenek
cat >> shopping_list.txt <<EOF

[cenek]
10x garlic
EOF
git add shopping_list.txt
git commit -m 'I want garlic soup'

git checkout master

# General more chocolate
sed -i 's/[0-9]x chocolate/3x chocolate/g' shopping_list.txt
git add shopping_list.txt
git commit -m 'More chocolates'

git checkout cenek
git branch cenek-bak
git rebase master
git checkout master
git merge cenek
git branch -d cenek
git branch -D cenek-bak