From 3ee7bc74b4f8360bf03c397327e7e8ce69c0236e Mon Sep 17 00:00:00 2001 From: Roger Rutishauser Date: Wed, 16 Oct 2024 22:01:59 +0200 Subject: [PATCH] linux --- docker/README.md | 50 +++++++++ linux/README.md | 11 ++ linux/linux-bash-scripting.md | 198 ++++++++++++++++++++++++++++++++++ linux/linux-dateitypen.md | 79 ++++++++++++++ linux/linux-netzwerk.md | 77 +++++++++++++ linux/linux-ordnerstruktur.md | 75 +++++++++++++ linux/linux-vim.md | 28 +++++ 7 files changed, 518 insertions(+) create mode 100644 linux/README.md create mode 100755 linux/linux-bash-scripting.md create mode 100755 linux/linux-dateitypen.md create mode 100755 linux/linux-netzwerk.md create mode 100755 linux/linux-ordnerstruktur.md create mode 100755 linux/linux-vim.md diff --git a/docker/README.md b/docker/README.md index 13a6acf..b5f61ee 100644 --- a/docker/README.md +++ b/docker/README.md @@ -65,6 +65,56 @@ https://docs.docker.com/engine/install/centos/#install-using-the-repository https://docs.docker.com/engine/install/ubuntu/ +Nachfolgend eine Anleitung für Docker und Docker-Compose Intallation unter Ubuntu 20.04, aus folgenden Quellen + + - https://www.cloudbooklet.com/install-wordpress-with-docker-compose-nginx-apache-with-ssl/ + - https://shownotes.opensourceisawesome.com/running-wordpress-with-docker/ + +Fügen Sie Ihrem System dann den GPG-Schlüssel für das offizielle Docker-Repository hinzu + +``` +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - +``` + +Fügen Sie das Docker-Repository zu APT-Quellen hinzu + +``` +sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" +``` + +Aktualisieren Sie als Nächstes die Paketdatenbank mit den Docker-Paketen aus dem neu hinzugefügten Repo + +``` +sudo apt update +``` + +Stellen Sie sicher, dass Sie aus dem Docker Repo und nicht aus dem Standard-Ubuntu-Repo installieren + +``` +apt-cache policy docker-ce +``` + +docker installieren + +``` +sudo apt install docker-ce +sudo usermod -aG docker ${USER} +``` + +prüfen ob docker ausgeführt wird + +``` +sudo systemctl status docker +``` + +installieren von docker-compose + +``` +sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose +``` + +(neuste Version unter https://github.com/docker/compose/releases) + ## configure log https://docs.docker.com/config/containers/logging/configure/ diff --git a/linux/README.md b/linux/README.md new file mode 100644 index 0000000..b426269 --- /dev/null +++ b/linux/README.md @@ -0,0 +1,11 @@ +## Linux + +[Dateitypen](linux-dateitypen.md) + +[Ordnerstruktur](linux-ordnerstruktur.md) + +[Netzwerk](linux-netzwerk.md) + +[Bash Scripting](linux-bash-scripting.md) + +[VIM](linux-vim.md) \ No newline at end of file diff --git a/linux/linux-bash-scripting.md b/linux/linux-bash-scripting.md new file mode 100755 index 0000000..803ab79 --- /dev/null +++ b/linux/linux-bash-scripting.md @@ -0,0 +1,198 @@ +--- +gitea: none +include_toc: true +--- +# Bash Scripting + +Bash (für Bourne-again shell) ist eine freie Unix-Shell und Teil des GNU-Projekts. + +There are some conventions to follow to ensure that your computer is able to find and execute your Bash scripts. The beginning of your script file should start with `#!/bin/bash` on its own line. This tells the computer which type of interpreter to use for the script. When saving the script file, it is good practice to place commonly used scripts in the `~/bin/` directory. + +The script files also need to have the “execute” permission to allow them to be run. To add this permission to a file with filename: script.sh use: `$ chmod +x script.sh`. To ensure that scripts in `~/bin/` are available, you must add this directory to your `PATH` within your configuration file: `PATH=~/bin:$PATH`. The configuration file is `~/.bashrc` (Linux) or `~/.bash_profile` (OSX). Now any scripts in the `~/bin` directory can be run from anywhere by typing the filename. + +## Variable + +``` +greeting="Hello" +echo $greeting +``` + +## Conditionals + +A complete conditional in a bash script uses the following syntax: + +``` +if [ $index -lt 5 ] +then + echo $index +else + echo 5 +fi +``` + +Bash scripts use a specific list of operators for comparison. Here we used -lt which is “less than”. The result of this conditional is that if $index is less than 5, it will print to the screen. If it is 5 or greater, “5” will be printed to the screen. + +Here is the list of comparison operators for numbers you can use within bash scripts: + +``` +Equal: -eq +Not equal: -ne +Less than or equal: -le +Less than: -lt +Greater than or equal: -ge +Greater than: -gt +Is null: -z +``` + +When comparing strings, it is best practice to put the variable into quotes ("). This prevents errors if the variable is null or contains spaces. The common operators for comparing strings are: + +``` +Equal: == +Not equal: != +``` + +For example, to compare if the variables foo and bar contain the same string: `if [ "$foo" == "$bar"]` + +## Loops + +### for loop + +``` +for word in $paragraph +do + echo $word +done +``` + +### while/until loops + +Within bash scripting until and while are very similar. while loops keep looping while the provided condition is true whereas until loops loop until the condition is true. + +``` +while [ $index -lt 5 ] +do + echo $index + index=$((index + 1)) +done + +until [ $index -eq 5 ] +do + echo $index + index=$((index + 1)) +done + + +# example: + +#!/bin/bash +first_greeting="Nice to meet you!" +later_greeting="How are you?" +greeting_occasion=0 +while [ $greeting_occasion -lt 3 ] +do + if [ $greeting_occasion -lt 1 ] + then + echo $first_greeting + else + echo $later_greeting + fi + greeting_occasion=$((greeting_occasion + 1)) +done +``` + +## arrays + +### declare + +``` +declare ELEMENTS=("value1" "value2") +``` + +### loop values + +``` +for e in "${ELEMENTS[@]}"; do echo "$e" done +``` + +### associative arrays + +``` +declare ELEMENTS=(["key1"]="value1" ["key2"]="value2") + +# loop keys: +for e in "${!ELEMENTS[@]}"; do echo "$e" done + +# loop values: +for e in "${ELEMENTS[@]}"; do echo "$e" done +``` + +## User Input + +### Read + +``` +echo "Guess a number" +read number +echo "You guessed $number" +``` + +### Options + +``` +#!/bin/bash + +# Bash Menu Script Example + +PS3='Please enter your choice: ' +options=("Option 1" "Option 2" "Option 3" "Quit") +select opt in "${options[@]}" +do + case $opt in + "Option 1") + echo "you chose choice 1" + ;; + "Option 2") + echo "you chose choice 2" + ;; + "Option 3") + echo "you chose choice $REPLY which is $opt" + ;; + "Quit") + break + ;; + *) echo "invalid option $REPLY";; + esac +done +``` + +## access files + +``` +files=/some/directory/* +# You can then iterate through each file and do something. Here, lets just print the full path and filename: + +for file in $files +do + echo $file +done +``` + +### iterate file line by line + +assuming you have a file `delete.txt` with id's line by line. + +``` +#!/bin/bash + +input="delete.txt" +while IFS= read -r line +do + mysql -uroot -pD66-twcpaeb -e "use atom; delete from object where id = $line" +done < "$input" +``` + +## echo to console AND log file + +``` +echo "Some console and log file message" | tee /home/user/logfile.log +``` diff --git a/linux/linux-dateitypen.md b/linux/linux-dateitypen.md new file mode 100755 index 0000000..0422a72 --- /dev/null +++ b/linux/linux-dateitypen.md @@ -0,0 +1,79 @@ +--- +gitea: none +include_toc: true +--- +# Dateitypen + +## Reguläre Datei + +zu ergänzen... + +## Ordner + +Bei `ls -la` markiert mit `d` am Anfang. + +## Blockgeräte Datei + +Zu finden bspw. in `/dev`, markiert mit `b` am Anfang. + +## Charactergeräte Datei + +Treiber oder sonstige Hardware Konfig Dateien. + +Dump von Block- oder Charaktergeräte-Datei. + +``` +hexdump -n 512 -CH netzwerk.conf +``` + +Wenn man davon über ganze Festplatte machen würde, könnte man ISO Datei schreiben, gut für Backup oder für USB-Stick oder Clone auf andere Festplatte. + +Zu finden bspw. in `/dev`, markiert mit `c` am Anfang. + +## Named Pipes + +Anonyme Pipes `|` sind nicht bi-direktional, können nicht mit grösseren Datenmengen umgehen etc. Deshalb gibt es named pipes, wo das alles möglich ist. + +Named Pipes werden also auch als Datei abgespeichert. Erstellen mit `mkfifo meinepipe`. Bei `ls -la` markiert mit `p` am Anfang. + +In diese Datei können nun Programme und Prozesse Sachen rein schreiben und raus nehmen. Bsp.: + +``` +# Ist-Zustand einer Logdatei in Pipe speichern: +cat /var/log/messages > meinepipe + +# Ausgabe einer Logdatei so lange in Pipe schreiben (im Hintergrund), bis sie abgeholt wird: +cat /var/log/messages > meinepipe & + +# Nun kann in einem zweiten Terminal die Pipe ausgelesen werden, welches zugleich die Pipe leert. +cat meinepipe +``` + +## Lokale Socket Datei + +Z.B. wenn Apache mit PHP Prozess zusammen kommunizieren. Oder Syslog zu anderen Apps. + +Zu finden bspw. in `/var/run/...`, markiert mit `s` am Anfang. + +## Symbolischer Link + + - Softlink, Verweis auf die richtige Datei. Markiert mit `l` am Anfang. + ``` + ln -s /usr/share/nginx/atom home/rogrut/atom + ``` + - Hardlink, Duplizierung auf den selben Bereich auf der HD. + ``` + ln /home/rogrut/.ssh/authorized_keys /home/rogrut/ak + + # ls zeigt dann ein 2 an bei der Datei. + + ls -lni /home/rogrut/.ssh/authorized_keys + 131928 -rw-------. 2 1000 1000 1156 Jun 8 23:25 /home/rogrut/.ssh/authorized_keys + + ls -lni /home/rogrut/ak + 131928 -rw-------. 2 1000 1000 1156 Jun 8 23:25 /home/rogrut/ak + ``` + +Wenn man 1 davon löscht, ist die andere immernoch vorhanden. + +Wenn man 1 davon ändert, wird die andere auch geändert. \ No newline at end of file diff --git a/linux/linux-netzwerk.md b/linux/linux-netzwerk.md new file mode 100755 index 0000000..1b7b736 --- /dev/null +++ b/linux/linux-netzwerk.md @@ -0,0 +1,77 @@ +--- +gitea: none +include_toc: true +--- +# Linux Netzwerk + +## Interface + +Jedes Interface hat einen eigenen Namen welches konfiguriert werden muss + + - `en*`: Physisches Ethernet Interface + - `wl*`: Physisches WLAN Interface + - `ww*`: Physiche WWAN Interace (Cellphone Card, Network Address) + - `eth*`: Virtuelles Interface (VMs, Cloud Instanzen) + - `vir*`: VirtualBox + +`route` shows used Interface. + +## Get hostname + +``` +hostname +``` + +## Get public IP address + +IPv4: + +``` +dig TXT +short o-o.myaddr.l.google.com @ns1.google.com +or +host myip.opendns.com resolver1.opendns.com +``` + +IPv6: + +``` +dig -6 TXT +short o-o.myaddr.l.google.com @ns1.google.com +``` + +## Network configuration with nmcli + +### Show available wifi + +``` +nmcli device wifi list +``` + +### show network interfaces on computer + +``` +ip link show +or +nmcli device +``` + +### show interface information + +Shows table with local IP, Gateway IP, DNS IP, network name etc. + +``` +nmcli con show + +NAME UUID TYPE DEVICE +RR_Net 9a0bf331-2197-478e-aaef-8bdb0da7daef wifi wlp1s0 +``` + +``` +nmcli dev show +``` + +For hardware info: + +``` +lshw -C network +``` + diff --git a/linux/linux-ordnerstruktur.md b/linux/linux-ordnerstruktur.md new file mode 100755 index 0000000..9e6aa12 --- /dev/null +++ b/linux/linux-ordnerstruktur.md @@ -0,0 +1,75 @@ +--- +gitea: none +include_toc: true +--- +# Linux Ordnerstruktur + +## /bin + +System-Tools, die alle Benutzer ausführen können. Z.B. auch `chmod` oder `ls` + +## /sbin + +Programme für Systemadministration, wo es Root-Rechte braucht. `fdisk`, `shutdown` etc. + +## /boot + +Bootloader wie Grub2, die für Bootvorgang erforderlichen Dateien, und Kernel. + +## /dev + +Gerätedateien. Zeichen und Blockorientierte Spezialdateien, die den Zugirff wie HDD, DVD oder Schnittstellen steuern. + +## /etc + +Systemkonfigurationsdateien, auch für Apps. + +## /home + +"Eigene Dateien" für jeden Benutzer + +## /lib + +Bibliotheken und Kernel-Modulen ("lib" in Windows) + +## /media + +Zugriff auf USB-Sgticks, DVD, Externe HDDs etc + +## /mnt + +Mountpunkt gedacht um kurz ein Dateisystem einzuhängen, z.B. Netzwerkspeicher + +## /opt + +"Optional", selbstinstallierte Programme. Bei Installationen über Paketdienste nicht im `/opt`. + +## /proc + +Prozess- und Systeminformationen. Werden von Prozess dynamisch generiert. Wenn Prozess nicht da, Datei in `/proc` auch nicht mehr. Enthält Infos über Prozess in Dateien benannt nach der PID. + +## /root + +Ordner des Root, Administrator. + +## /srv + +System-Dienste wo CGI-Skripts, Web oder FTP-Server laufen. Wird nicht mehr oft verwendet + +## /tmp + +Zwischenlager für Dateien + +## /usr + +Dateien für alle Benutzer, z.B. von Programmen wo keine Root-Rechte nötig. Z.B. Photoshop, AtoM etc + +## /var + +Variable Daten - Druckerspool, Mail, Web, DB, Log-Dateien. + +Allenfalls sinnvoll, `/var` wegen den log-Dateien auf separate Partition zu mounten, damit riesiges Log nicht Systemabsturz verursacht. + +## /home + +"Eigene Dateien" für jeden Benutzer \ No newline at end of file diff --git a/linux/linux-vim.md b/linux/linux-vim.md new file mode 100755 index 0000000..cb47e5c --- /dev/null +++ b/linux/linux-vim.md @@ -0,0 +1,28 @@ +--- +gitea: none +include_toc: true +--- +# VIM + + - `i` Insert mode, `ESC` insert mode beenden + - `w` speichern + - `w neue-datei.txt` speichert Inhalt in neue Datei. + - `q` beenden + - `v` visual mode, zum markieren, mit `y` kopieren, dann `p` zum einfügen + - 2x `y` ganze Zeile kopieren, mit `p` einfügen + - 2x `d` ganze Zeile löschen + - `3 dd` 3 Zeilen löschen + - `/suchbegriff` suchen, nächstes Vorkommen mit `n` + +## Change Color Theme + +```:colo murphy``` + +## Search and Replace + +``` +:%s/foo/bar/g +``` + +weitere Möglichkeiten: https://vim.fandom.com/wiki/Search_and_replace +