Konsolenschnipsel: Unterschied zwischen den Versionen

Aus TippvomTibb
Zur Navigation springen Zur Suche springen
Zeile 151: Zeile 151:
 
In OpenSuSE 15.3 gabe es noch keine profile.local. Also  
 
In OpenSuSE 15.3 gabe es noch keine profile.local. Also  
 
  vi /etc/profile.local
 
  vi /etc/profile.local
+
 
 +
<pre>
 
  alias psgrep='ps ax|grep -v grep|grep'
 
  alias psgrep='ps ax|grep -v grep|grep'
 
  alias fing='function _fing(){ find "$1" -type f -exec grep -l "$2" {} \; ; }; _fing'
 
  alias fing='function _fing(){ find "$1" -type f -exec grep -l "$2" {} \; ; }; _fing'
 
  alias histg="history | grep"
 
  alias histg="history | grep"
 
  alias myip="curl http://ipecho.net/plain; echo"
 
  alias myip="curl http://ipecho.net/plain; echo"
 +
</pre>
  
 
und zum Abschluss
 
und zum Abschluss

Version vom 16. August 2022, 08:02 Uhr

Hier sammele ich ohne weiteren Zusammenhang Schnipsel, die mir die Consolenarbeit erleichtern.

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

Useful Examples

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'

Kapitel 3.2.5

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