Konsolenschnipsel: Unterschied zwischen den Versionen
Zeile 177: | Zeile 177: | ||
9 32 3.18408% aplay | 9 32 3.18408% aplay | ||
10 31 3.08458% history | 10 31 3.08458% history | ||
+ | |||
+ | =Bash regex= | ||
+ | Es ist zum .... | ||
+ | Gerade eben einen regulaeren Ausdruck zusammengebaut und [https://regex101.com/ mit] getestet. Dann in ein Bash-Script eingebaut und POW! | ||
+ | Lange Suche kurzer Sinn. Bash kennt keine (nicht alle) Kurzschreibweisen. Normalerweise sind z.B. diese Schreibweisen gleichbedeutend: | ||
+ | |||
+ | [[:digit:]] = [0-9] = \d | ||
+ | |||
+ | Aber Bash (grep, sed?) kennt das \d nicht!!! | ||
+ | The \d exists in less instances than [[:digit:]] (available in grep -P but not in POSIX). | ||
+ | |||
+ | Ausloeser war eigentlich das Problem, dass meine Soundkarte/Soundchip (MCP73) in einen Stand schaltet sobald 'alsa' keine (Audio-)Daten schickt. Das machte sich in einem Dauerrauschen bemerkbar, wenn keine Audiodatei abgespielt wurde. Mit | ||
+ | |||
+ | aplay -Dplug:dmix /dev/zero | ||
+ | |||
+ | war Stille. Dumm nur, dass der Task nach unbstimmter Zeit (Programmfehler) abbricht, also musste ein Script her, welches von cron aufgerufen werden kann. | ||
+ | |||
+ | <syntaxhighlight lang="bash" line> | ||
+ | #! /bin/bash | ||
+ | output=$(ps ax|grep -v 'grep'|grep -v $0 |grep 'aplay') | ||
+ | [[ $output =~ ^([[:digit:]]+).+(aplay -Dplug:dmix /dev/zero) ]] | ||
+ | #output="19178 pts/0 SL 0:46 aplay -Dplug:dmix /dev/zero" | ||
+ | #[[ $output =~ ^([0-9]+)(.*)$ ]] # zum Testen | ||
+ | #echo "${output}" | ||
+ | #echo "${BASH_REMATCH[0]}" | ||
+ | #echo "1: ${BASH_REMATCH[0]}" | ||
+ | #echo "2: ${BASH_REMATCH[1]}" | ||
+ | if [ -z "${BASH_REMATCH[1]}" ]; | ||
+ | then | ||
+ | exec aplay -Dplug:dmix /dev/zero & | ||
+ | fi | ||
+ | </syntaxhighlight> |
Version vom 17. August 2022, 10:35 Uhr
Hier sammele ich ohne weiteren Zusammenhang Schnipsel, die mir die Consolenarbeit erleichtern.
Inhaltsverzeichnis
rsync
Benutze ich am liebsten um sicher zu stellen, dass bei einem Übertragen eines Verzeichnisses nichts schiefgeht und wenn doch bekommt man es wenigstens mit.
rsync -avPh --stats Quelle Ziel
Korrektur: Da -a folgende Optionen zusammenfasst:
-r kopiert Unterverzeichnisse -l kopiert symbolische Links -p behält Rechte der Quelldatei bei -t behält Zeiten der Quelldatei bei, -g behält Gruppenrechte der Quelldatei bei -o behält Besitzrechte der Quelldatei bei (nur root) -D behält Gerätedateien der Quelldatei bei (nur root)
ist 'p' doppelt gemoppelt. Hier war von mir das grosze P gewollt.
diff
Um nach einem Übertragen von Daten auf Nummer Sicher zu gehen.
diff -r Ordner1/ Ordner2/
adb
Neben einem MTP-Backup immer noch meine Lieblingsmethode um meine Tablets/Smartphones zu sichern.
adb devices
adb backup --all
oder besser
adb backup "-apk -shared -all -f C:\Users\NAME\backup.ab"
Entpacken des "backup.ab"-Files.
( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 backup.ab ) | tar xfvz -
Näheres hierzu siehe. https://www.gnu.org/software/tar/manual/html_node/Standard.html
simple-mtpfs
Super um über MTP zu mounten.
https://github.com/phatina/simple-mtpfs/
1 #! /usr/bin/env bash
2 #Script for simple-mtpfs
3 PS3=$'\nSelect an option.: '
4 #mount directory
5 dir="/media/myphone"
6 while :; do
7 clear
8 options=('Quit' 'List Devices' 'Mount' 'Umount')
9 select opt in "${options[@]}"; do
10 case "$opt" in
11 Quit) clear; exit
12 ;;
13
14 'List Devices') simple-mtpfs -l
15 ;;
16
17 Mount) simple-mtpfs "$dir"; echo "Mounted to "$dir""
18 ;;
19
20 Umount) fusermount -u "$dir"; echo "Unmounted"
21 ;;
22 esac
23 done
24 done
Quelle: [1]
alias raspi
alias l='ls -alF' alias la='ls -la' alias ll='ls -l' alias ls='_ls' alias ls-l='ls -l' alias md='mkdir -p' alias o='less' alias rd='rmdir'
bash .alias
Unter Suse war im ~root kein bashrc vorhanden. Beim Anlegen eines neuen Users wird eine default-Version normalerweise aus /etc/skel ins (neue) Heimatverzeichnis umkopiert. In dieser Datei (etc/skel/.bashrc) findet sich folgender Hinweistext.
# There are 3 different types of shells in bash: the login shell, normal shell # and interactive shell. # Login shells read ~/.profile and # interactive shells read ~/.bashrc; # in our setup, /etc/profile sources ~/.bashrc - thus all # settings made here will also take effect in a login shell.
Login/Interactive Shell 1 Login/Interactive Shell 2
For example, if you login to bash using an xterm or terminal emulator like putty, then the session is both a login shell and an interactive one. If you then type bash then you enter an interactive shell, but it is not a login shell.
When a login bash shell is invoked, then /etc/profile is sourced (executed in the current environment). After that, three files are checked for existence. The checks for these files are done in this order:
if /etc/profile exists, source (run) it if ~/.bash_profile exists, source (run) it if ~/.bash_login exists, source (run) it if ~/.profile exists, source (run) it
/etc/profile sollte man aber nicht veraendern!
# PLEASE DO NOT CHANGE /etc/profile. There are chances that your changes # will be lost during system upgrades. Instead use /etc/profile.local for # your local settings, favourite global aliases, VISUAL and EDITOR # variables, etc ...
Also dann alles folgende in die etc/profile.local, damit auch alle Nutzer was davon haben;-)
alias histg="history | grep" alias myip="curl http://ipecho.net/plain; echo"
alias psgrep='ps ax|grep -v grep|grep'
TODO: Special Variables $$, $1, $@, ...
um z.B. sowas hinzubekommen:
alias fing='function _fing(){ find "$1" -type f -exec grep -l "$2" {} \; ; }; _fing'
Das Ding hat mich Nerven gekostet. Das Problem war die zwie Semicolon am Ende in der Funktion. Das erste \; schlieszt das exec ab, das zweite ; den find Befehl.
Eventuell kannman das auch als alias gebrauchen.
rmv() { mv "$2/${1##*/}" "${1%/*}" ; }
Funktion im alias
Probier mal
alias echotest='f(){ /usr/bin/echo "$1" "$2" "$@"; };f'
oder
alias echotest='function testecho(){ /usr/bin/echo "$1" "$2" "$@"; };testecho'
Fuer Eilige
In OpenSuSE 15.3 gabe es noch keine profile.local. Also
vi /etc/profile.local
alias psgrep='ps ax|grep -v grep|grep' alias fing='function _fing(){ find "$1" -type f -exec grep -l "$2" {} \; ; }; _fing' alias histg="history | grep" alias myip="curl http://ipecho.net/plain; echo"
und zum Abschluss
source /etc/profile.local
und freuen.
History Statistik
history | awk '{CMD[$4]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10 1 71 7.06468% systemctl 2 66 6.56716% cd 3 63 6.26866% vi 4 63 6.26866% ll 5 40 3.9801% find 6 38 3.78109% zypper 7 34 3.38308% locate 8 32 3.18408% ps 9 32 3.18408% aplay 10 31 3.08458% history
Bash regex
Es ist zum .... Gerade eben einen regulaeren Ausdruck zusammengebaut und mit getestet. Dann in ein Bash-Script eingebaut und POW! Lange Suche kurzer Sinn. Bash kennt keine (nicht alle) Kurzschreibweisen. Normalerweise sind z.B. diese Schreibweisen gleichbedeutend:
digit: = [0-9] = \d
Aber Bash (grep, sed?) kennt das \d nicht!!!
The \d exists in less instances than digit: (available in grep -P but not in POSIX).
Ausloeser war eigentlich das Problem, dass meine Soundkarte/Soundchip (MCP73) in einen Stand schaltet sobald 'alsa' keine (Audio-)Daten schickt. Das machte sich in einem Dauerrauschen bemerkbar, wenn keine Audiodatei abgespielt wurde. Mit
aplay -Dplug:dmix /dev/zero
war Stille. Dumm nur, dass der Task nach unbstimmter Zeit (Programmfehler) abbricht, also musste ein Script her, welches von cron aufgerufen werden kann.
1 #! /bin/bash
2 output=$(ps ax|grep -v 'grep'|grep -v $0 |grep 'aplay')
3 [[ $output =~ ^([[:digit:]]+).+(aplay -Dplug:dmix /dev/zero) ]]
4 #output="19178 pts/0 SL 0:46 aplay -Dplug:dmix /dev/zero"
5 #[[ $output =~ ^([0-9]+)(.*)$ ]] # zum Testen
6 #echo "${output}"
7 #echo "${BASH_REMATCH[0]}"
8 #echo "1: ${BASH_REMATCH[0]}"
9 #echo "2: ${BASH_REMATCH[1]}"
10 if [ -z "${BASH_REMATCH[1]}" ];
11 then
12 exec aplay -Dplug:dmix /dev/zero &
13 fi