+++
title = 'Linux'
date = 2024-02-08T21:38:20+01:00
draft = false
+++

{{< style_regular >}}


{{< toc >}}

# Notes and source
Notes based on: <https://geek-university.com/course/free-linux-course/> (as of 2020)

**This page is the only English one, as it's the only learning resource we used that is not in German!**

# Important directories
- `/boot`   -> boot files
- `/bin`    -> pre-installed executables
- `/dev`    -> devices (i.e. hard drive, etc.)
- `/sbin`   -> pre-installed executables that require root
- `/etc`    -> configuration
- `/home`   -> user data
- `/lib`    -> shared libraries
- `/media`  -> removable media
- `/usr`    -> shared data (i.e. wallpapers, fonts, applications, etc.)
- `/var`    -> variable data (i.e. logs, etc.)
- `/tmp`    -> temporary data (gets wiped at boot)

# How to install Linux
- Go to official website
- Download ISO
- Flash USB-Drive
- Boot into ISO (boot order or one-time boot menu)
- Install

# Shell
- Interprets commands
- Run via terminal emulator
- Examples:
  - bash
  - zsh
  - korn shell (ksh)

# Bash
- Standard shell on most systems
- "Bourne Again SHell"

# Links
- Soft / hard links
- Soft link = symlink
- Symlink = points to file or directory
- Hard link = points to inode (place on hd/ssd)
- `ln`


# Wildcards
- `?`     -> any single character
- `*`     -> any string of any length
- `[ ]`   -> any single character mentioned in the brackets

# Streams
- 3 streams
- Standard input (STDIN)
- Standard output (STDOUT)
- Standard error (STDERR)

# Redirection
| Symbol | Redirects to / from                                   |
|--------|-------------------------------------------------------|
| >      | redirect stdout to file (create/overwrite)            |
| >>     | redirect stdout to file (create/append)               |
| 2>     | redirect stderr to file (create/overwrite)            |
| &>     | redirect stdout and stderr to file (create/overwrite) |
| <      | redirect file to stdin (create/overwrite)             |
| <<     | redirect file to stdin (create/append)                |

# Piping
`command1 | command2`

- output of command1 used as stdin for command2

# Some noteworthy commands
## Sort
`sort file.txt`

Sorts files alphabetically. See `man sort` for more info

## Find
`find [path] [expression]`

Searches directories and sub-directories for files. See `man find` for more info

## Locate
`locate [pattern]`

Searches for files (less complicated than find). See `man locate` for more info
 
## Word count
`cat file | wc`

Counts words, lines, etc in files. See `man wc` for more info

## File
`file file.extension`

Takes an "educated guess", what type of file `file.extension` is

## Head / Tail
`cat file | head` and `cat file / tail`

Show only a select number of lines, starting at the top (head) or at the bottom (tail)

See `man head` and `man tail` for more info

## Tar
Is used to compress/extract folders and files. See `man tar` for more info

# Processes
## Interfacing with processes
- ps
- htop
- kill
- killall

## Signals
Signals are sent to processes to "tell" them what to do. Most important signals:

| Signal  | Description                           |
|---------|---------------------------------------|
| SIGKILL | forcefully stop process               |
| SIGTERM | stop process and associated processes |
| SIGSTOP | pause process                         |
| SIGCONT | continue process                      |

# Installing applications
- Depends on distro

| Distro | Package command |
|--------|-----------------|
| Debian | apt             |
| RedHat | yum             |
| Arch   | pacman          |
| Gentoo | emerge          |

# User management
Commands: `usermod`, `groupmod`

## /etc/passwd
`username:password:UID:GID:comment:homedir:login shell`

# Permissions
- 3 permissions
    - `r`   -> read
    - `w`   -> write
    - `x`   -> execute
- 3 classes
    - Owner
    - Group
    - Rest

Arranged like this:
```
| owner     | group     | other     |
| r | w | x | r | w | x | r | w | x |
```

# File systems
Handles the way that data is stored. Linux is compatible with a lot of them:

- ext4 (deprecated: ext3 / ext2 / ext)
- BtrFS
- ReiserFS
- XFS
- ZFS
- FAT
