Von schwarzen Fenstern mit weissem Text und Rohren
Von schwarzen Fenstern mit weissem Text und Rohren
[user@machine ~]$ | Part | Bedeutung |
|---|---|
user | Nutzername |
machine | Hostname des Rechners |
~ | Ordner |
uname --operating-systemuname --operating-system
cat file.txt file2.txtcat file.txt file2.txt
--color red setzte eine Option auf einen bestimmten Wert--flag schaltet eine bestimmte Option ein--option wird zu -o)Definiert durch Ken Thompson und dokumentiert durch Doug McIlroy im Bell System Technical Journal (1978)
tldr: Funktionaler Ansatz, analog zu Funktionsaufrufen, Argumenten und Rueckgabewerten d.h.:
history[thilo@my-distrobox ~]$ history 1 whereis zsh 2 sudo nano /etc/fstab 3 sudo mkdir -p /data 4 sudo mount -a 5 ls 6 cd /data/ 7 ls 8 cd .. 9 cd /home/thilo/ 10 clear[thilo@my-distrobox ~]$ history 1 whereis zsh 2 sudo nano /etc/fstab 3 sudo mkdir -p /data 4 sudo mount -a 5 ls 6 cd /data/ 7 ls 8 cd .. 9 cd /home/thilo/ 10 clear
exitpwd - Aktuellen Pfad anzeigen
[thilo@my-distrobox ~]$ pwd /home/thilo[thilo@my-distrobox ~]$ pwd /home/thilo
cd path/to/directory - gehe zu einem bestimmten Ordnercd .. - gehe einen Ordner zurueckcd - gehe ins Home Verzeichnisls - listet aktuelles Verzeichnis aufls -a - listat alle Dateien im Verzeichnis aufls -l - listat aktuelles Verzeichnis detailliert auffile - liefert Informationen über Dateienless - Datei lesencp - Kopiere Dateien von a nach bcp -r - Kopiere Dateien rekursiv (also Ordner)mv - Verschiebe Dateien von a nach bmkdir - Erstelle Ordnermkdir -p - Erstelle Ordner und Elternordner falls nicht vorhandenrm - Dateien loeschenln -s - Symlink erstellenProgrammausgaben können in Dateien geschrieben werden
command > file command 1> filecommand > file command 1> file
Programmfehler ebenfalls
command 2> filecommand 2> file
und auch gleichzeitig
command 2> errorfile 1> filecommand 2> errorfile 1> file
und auch beides in eine Datei
command &> filecommand &> file
Wir können jetzt Output in Dateien schreiben, aber wie verknüpfen wir Programme mitenander.
command1 | command2 | command3 | ...command1 | command2 | command3 | ...
Beispiel
uname -r | lessuname -r | less
Dateien zusammenfuegen
cat file1 file2 file3 cat file1 file2 > output_filecat file1 file2 file3 cat file1 file2 > output_file
Sortiere Dateien oder Output
sort filesort file
sort file | uniqsort file | uniq
grep "expr" filegrep "expr" file
wc --lines filewc --lines file
head --lines 10 file head --bytes 10 filehead --lines 10 file head --bytes 10 file
Analog zu head
tail --follow filetail --follow file
Eigentlich ein einfaches print
echo "Hallo Welt" echo "$PATH"echo "Hallo Welt" echo "$PATH"
Umgebungsvariablen sind quasi globale Variablen, auf die wir immer Zugriff haben.
echo "$HOSTNAME"echo "$HOSTNAME"
PS1 (prompt string 1)echo "$SHELL"echo "$SHELL"
#!/usr/bin/env bash # Befehl echo Hallo # Variable Name="Thilo" # Befehl mit Variable echo $Name # Kontrollstrukturen if [ $Name != "Thilo" ] then echo "Schade, du bist jemand anderes" else echo "Freut mich, dass du es bist" fi # Loops for Zahl in {1..5} do echo "$Zahl" done#!/usr/bin/env bash # Befehl echo Hallo # Variable Name="Thilo" # Befehl mit Variable echo $Name # Kontrollstrukturen if [ $Name != "Thilo" ] then echo "Schade, du bist jemand anderes" else echo "Freut mich, dass du es bist" fi # Loops for Zahl in {1..5} do echo "$Zahl" done