<h1>LinuxLinux Shell:</h1> //ALGEMEIN --- ls -l ==> listet alle Ordner auf in sich befindendem Ordner pwd ==> Zeigt Ordnerpfad an sudo ==> wechselt zu adimistartorbenutzer apt install ProgrammXY ==> installiert programm mkdir ==> erstellt Ordner touch file.xy ==> erzeugt file oder gibt neues Speicherdatum nano ==> erzeugt file + berabeiung öffnet sich (oder wen file existiert nur bearbeiten) su ==> switch user rm *.txt ==> alle TXT files im sich befindendem Ordner löschen rm -r directory ==> löscht directory man + befehl ==> hilfe ping 192.168.43.108 endlos pings bis ctrl + c ping -c 5 192.168.43.108 ==> 5 Pings (nicht endlos) htop ==> processe alias ==> man kann eigene Befehler creiieren ==> alias erase=rm (rm ==Y remove) tar -tzf ==> tar = in 1 file schriben -z = zippen(komprimieren) ls -lisah -R /home/pi ==> liste alle Files von /home/pi inkl unterverzeichnisse (durch gross R) ls -l -R /home/pi > file.txt schreibt der Befehl oben in ein txt ls -l -R /home/pi >> file.txt anhängend an text in File - schriebt den Befehl oben in ein txt who ==> zeigt user die eingeloggt sind w ==> zeigt dasselbe uptime ==> wie lange schon eingeloggt which ==> zeigt pfad von file an ls /usr/bin/xy -l ==> zeigt "hardlink / alias" an, wo file liegt //SUCHFUNKTIONEN --- find -name traini* ==> sucht alles im Ordner mit traini.... grep "text" * -r ==> -r = auch in unterordner sonst nur im alktuellem ordner ==> * = in allen files ==> "text" = sucht nach text innerhalb der Files file filenam.evtnExtension ==> zeigt an was für ein Filetyp es ist type mosquitto_pub ==> zeigt Pfad des Files an(nur executable files) cd ~ ==> change directory to home //HARDLINK --- ln -s datein.txt verlinkt auf Datei (symbolischer link) ln = hardlink //SSH & Filetransfer --- ssh pi@192.168.43.108 ==> ssh verbindung aufbauen scp *.txt pi@192.168.43.108:Sport ==> kopiert über Netzwerk alle .txt files an IP in den Ornder Sport BSP cmd windows: scp pi@192.168.43.108:/home/pi/file.txt ./01_MeineWindowsDaten/ BSP 2: scp pi@192.168.43.208:scripts/* ./ (alle files im ordner scripts) scp pi@10.100.129.218:/home/pi/mqtt-rtk/* ./ //PROGRAMMSTATUS UND NEUSTART VON PROGRAMEN --- systemctl r (+tab) restart, reboot ... etc als möglichkeit s (+tab) start, stop, status ... BSP: sudo systemctl restart mosquitto.service sudo systemctl is-enabled ssh ==> Ob dienst aktiv ist sudo systemctl enable ssh ==> aktiviert ssh (auch bei reboot wird danach ssh noch aktiv sein) wie eine art Autostart ssh -L 80:localhost:80 pi@192.168.43.208 (Browser localhost) ssh -L 90:localhost:80 pi@192.168.43.208 (Browser localhost:90) -> 90 auf Windows -> 80 bei Raspi //MOSQUITTO --- mosquitto_pub -h localhost -t topic/untertopic -m "meine Message" mosquitto_sub -h localhost -t topic/untertopic ==> bleibt hangen in console ctrl + c & ctrl + c = beenden ctrl + z = stoppen //---> ---> bg (background läuft mosquitto_sub) ==> ich kann in console weiter schreiben, wen aber jemand publishd, schreibt es den text in die console! fg ==> forderground => normal (consolen einträge nicht möglich) ==> mit befehl xy | pipebefehl & kann es auch im background gemacht werden (das & für den prozess im hintergrund auf) ifconfig | grep inet | mousqutto_pub -h localhost -t topic -s ==> grep inet filtert nur inet aus ifconfig ==> -s nimmt eingangswerte und publiziert diese (eingangswerte immer von links) mqtt=====> -s eingangswert -f file -m message BSP2: uptime | mousqutto_pub -h localhost -t eingeloggteUser -s Temp raspi (nur physische): cat /sys/class/thermal/thermal_zone0/temp | mosquitto_pub .... nach install fswebcam und aktivieren diser webcam: sudo fswebcam -d /dev/video0 -r 640x480 --jpeg -1 abc.jpg | mosquitto_pub -h localhost -t pic/vbox -f abc.jpg APP mqtt dash kann bilder empfange //USER /-RECHTE --- Users: ls -s ==> zeigt files mit Users und permissons an 1. art des file: d = direcotry, - = normales file, l = verknüpfung (link) 2. Owner Permissions: r = read, - = not allowd 3. Owner Permissions: w = write, - = not allowd 4. Owner Permissions: x = executable (aufsühren), - = not allowd 5. Group Persmisions: r 6. Group Persmisions: w 7. Group Persmisions: x 8. Other Users: r 9. Other Users: w 10. Other Users: x chmod 777 = 2,3 & 4 rwx + 5,6 & 7 + 8,9 & 10 chmod 755 = (-) rwx r-x r-x chmod 644 = (-) rw- r-- r-- chmod +x file.txt = alle bekommen x chmod o-r file = remove "read" from user: Others chmod a+w file = add "write" for all users chmod 1. u = owner / a = all users / g = other users in group / o = other users 2. + / - 3. r, w oder x chown alain.alain (user.gruppe) Liste.txt = übergibt owner an alain des txts sudo useradd _username_ == erzeugt User sudo passwd _username_ == ändert Passwort von usere su _username_ == wechseln zu anderem User //Scripts --- #! /bin/bash x="hoi du" y=4 echo $x echo $y (echo zum ausgeben in cmd) BSP: #! /bin/bash xyz="ls -l" echo $xyz =>inhalt von xyz ==> (ls -l) echo "$xyz" => inhalt von xyz ==> (ls -l) echo '$xyz' => String ==> ($xyz) echo `$xyz` => inhalt variable ==> (werte des ls -l) = != -lt -gt => equal, not equal, lower than, grather then if[asdfasd = asdfasdf]; then echo "es ist gleicht" [else ...] echo "es ist nicht gleich" fi if [ -d "./directXY" ] ==> -d => ob directory existiert / -w => file hier inkl schreibrechte / -L & -h => file existiert then echo pfad existiert bereits else mkdir directXY fi cnt=1 while[ $cnt–lt6 ]; do echo "Counter:$cnt" cnt=$[$cnt+1] done for i in {1..9..5} do //iin 1 7 3; echo "$i" done for ((i=1; i < $MaxI; i++)) do blablabla done for file in ./school/*; do echo $file done ==> listet alle files und directorys auf im ordner school for file in *txt; do echo $file done ==> listet alle files .txt im sich befindendem Ordner auf echo 'xxxssss' >> irgendwo.txt hängt an echo 'vvvssss' > irgendwo.txt macht neues textfile / überschreibt text Inputs------- echo "your age" ==> frage read age ==> input age echo $age ==> output age Alternativ: read -p "your age" age ==> frage + input echo $age //AUTOMATISCH AUSFÜHREN VON SKRIPTS (Cronejob) --- script: #! /bin/bash echo `date > logfile denn crontab -e für automatisches aufrufen des Skripts (skript muss executable sein) min hour day month year /pfad/./skript */2 * * * * /home/pi/./meinskript ==> skript wird alles 2min ausgeführt 15 * * * * /home/pi/./meinskript ==> skript wird jede stunde um xx.15 ausgefürht @reboot /home/pi/./autostartskript proxmox port 8006