Direkt zum Inhalt

bash-scripting (Beispiele)

Hier werden ein paar Beispiele aus der "langweiligen" und "unspektakulären" schwarzen Konsole (Terminal) präsentiert. Die Text- oder Kommandozeilen-Konsole ist unter jedem Unix- (und Linux-) artigen Betriebssystem vorhanden, jederzeit aufrufbar und bei Unix- (Linux-) Freaks sehr beliebt.  (*)         
--------------------                     
(*) Um das Terminal unter Linux Mint zu starten, drücken Sie die sogenannte "Windows-Taste" oder Power-Taste. Die Taste wird so genannt, weil ein Windows-Logo darauf abgebildet ist; andere Namen für die Taste sind Super- oder Meta-Taste. Sie befindet sich zwischen den Tasten "Strg" und "Alt" unten links auf der Tastatur. Sobald Sie die Taste gedrückt haben, erscheint ein Menü und eine Suchleiste unten, in der Sie das Wort „Term“ eingeben sollten. Es erscheint eine Zeile mit der Überschrift:              
--------------------                     
„Terminal                       
Befehlszeile verwenden“                     
--------------------         

 Nach der Betätigung dieser Zeile erscheint schließlich die (bash) Konsole (oder Terminal), in der Sie Befehle eingeben können. Wenn Sie tiefer in die Materie eintauchen, werden Sie verstehen, wie hilfreich diese Konsole für Sie sein kann. Eine treffende Definition liefert uns Wikipedia: "eine Mensch-Maschine-Schnittstelle". Ein kurzes Beispiel, das dies beweist (für diejenigen, die noch einen alten PC mit einem CD-Rom Laufwerk haben):                
Das Kommando eject  

# eject

Nach dem Sie im Terminal das Kommando „eject“ eingegeben haben, betätigen Sie „Enter-Taste“:

Ihre CD-ROM Schublade wird "ausgespuckt".

Wenn Sie wiederum ein Befehl:

# eject -t

eingeben, wird CD-ROM Schublade wieder reingezogen.

Ja, es ist ganz simpel und trivial - aber ist das nicht toll?!

Mail aus der Kommandozeile 

#!/bin/bash                                
#### variablen definition anfang #########                                
A=`ls  /home/motion/motion | wc -l`                                
#### variablen definition ende #########

### falls die anzahl der bilder ändert sich, dann tu das und das ####                                
if [[ $A -ne 0 ]]                                
 then                                
            echo "alarm" | sudo mail -s "motionserver-kontrole"  test@test.de                                
else                                    
            echo "alles OK"                                
fi

-------------

Zwei Skripte um die Bilder zu optimieren

#!/bin/bash                                
mkdir /tmp/OPT;                                
for Y in `ls`;do convert  $Y  -resize 1200x900  $Y-opt.jpg ; mv *opt* /tmp/OPT; done;

# convert image.jpg -resize 50% image_new.jpg

3) GIF-Animation

# convert -delay 120 -loop 0 *.jpg GIF-Santa.gif

To reduce a pdf-file (pdf-file compression):

1) the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf $1.pdf

You can write that as a script for example:  "compress_pdf"

#!/bin/bash                                
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf  $1

and then execute:

./compress_pdf  your_original_file.pdf

as a result you get the following in the directory where you are:

your_small_file.pdf

------------

2) to give the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf orig_file.pdf

-----------------------

As a result: your original file "orig.pdf" will be your_small_file.pdf

For example:

orig.pdf      - 13,4 MB

your_small_file.pdf  -  519,4 KB

------------------------

3) gs -sDEVICE=pdfwrite -dCompatibilityLevel=4 -dNOPAUSE -dBATCH -r150 -sOutputFile=Zieldatei.pdf

And finally (if you have a lot of pdf-files), you can apply this script:

#!/bin/bash

PWD=pwd

cd $PWD

for A in `ls *pdf`; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}optimiert/$A.pdf $A;done

------------------

Head keyword "user" 

create user with bash

# useradd -m -d /home/iamauser -s /sbin/nologin  -G users  -c "i am a user" iamauser

user "iamauser" rename to jan

#usermod -l  jan  iamauser

.......................................

user jan new directory "/home/xyz"  to assign

# usermod -d /home/xyz -m jan                                
.......................................

user jan lock

# usermod -L jan

.............

user jan group sudo attach

# usermod -aG sudo jan

 delete user with home directory

# userdel -r User-Name 

# userdel -r jan

------------------

# ls -la big_file

-rw-rw-r--   1 user users  187603950   Jun 14 10:13 big_file

big_file = 179 MB  

I would like to splitting this file, for example into 10 MB files.

splitting:

# split -b 10m big_file  little_file_

Result:

-rwxrwxrwx 1 user user 187603950  Jan 23  2018 big_file                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aa                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ab                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ac                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ad                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ae                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_af                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ag                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ah                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ai                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aj                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ak                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_al                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_am                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_an                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ao                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ap                                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aq                                
-rw-rw-r-- 1 user user   9346030  Jan 23 11:32 litle_file_ar

 assemble:

cat little_file_* > big_file_result

ls -la big_file_result

-rwxrwxrwx 1 user user 187603950  Jan 23  2018 big_file_result

------------------

kill user (kill bill ;-)

sudo pkill -9 -u bill                                
pkill -9 -u bill                                
pgrep -u bill                                
ps -fp $(pgrep -d, -u bill)

------------------

Transfer the tar-archive via ssh to remote computer

#!/bin/bash                                
#### variablen definition anfang #########                                
datum=`date +"%d"``date +%"m"``date +"%y"`                                
#### variablen definition ende #########                                
tar -czf - /home/motion/  | ssh ferner-rechner  "cat > /home/$datum-bilder.tgz"

or in a line (without script)

# tar -cvf - /home/user123/ | ssh hostname  "cat > /tmp/user123.tar"

---------------

show "pure" ip-address (as numeral)

#ifconfig | head -2 | tail -1 | awk -F"inet" '{print $2}' | awk -F\  '{print $1}'

PS. Sometimes we are need (in scripts) only numeral number

-----------------

kill all processes as root

you must be root!

# echo k > /proc/sysrq-trigger

--------------

if cursor disappeared (is gone) (falls mauszeiger weg ist)

1) # gsettings set org.gnome.settings-daemon.plugins.cursor active false

---------------                                
2) # sudo modprobe -r psmouse

# sudo modprobe psmouse                                
---------------                                
3)  # xdotool mousemove 100 100

---------------------------

gnome console completely restarting:

# sudo service gdm restart

------------

show soundcard

# cat /proc/asound/cards

---------------------------

sound test: aplay

#  aplay /usr/share/sounds/alsa/Front_Center.wav

------------------------

check sound on the terminal

check sound -  the simple method on the terminal (for Linux Mint):

# aplay /usr/share/sounds/alsa/Front_Center.wav

if you hear words "front senter", then everything is ok!

ALSA: Advanced Linux Sound Architecture

Check it if if ALSA recognized your sound card:                                
# cat /proc/asound/cards                                
output (for example):

0 [Intel          ]: HDA-Intel - HDA Intel                                
                      HDA Intel at 0xfe6fc000 irq 26                                
 1 [VF0770         ]: USB-Audio - Live! Cam Sync HD VF0770                                
                      Creative Technology Ltd. Live! Cam Sync HD VF0770 at usb-0000:00:1d.7-4, high s

if output say:

"no soundcards"

then:

# lspci | grep -i audio

output (for example):

# 00:1b.0 Audio device: Intel Corporation NM10/ICH7 Family High Definition Audio Controller (rev 01)

if your system does not provide any output,  then you have bad luck, respectively have you bad sound cards :-(

-------------

show linux version 

# lsb_release -a

# cat  /etc/issue

---------------------------

f you have American keyboard and want to change to others, then:

# sudo apt-get install console-data                                
# sudo dpkg-reconfigure keyboard-configuration                                
# sudo apt-get update

---------------------------

Das Skript "zufallsgenerator"- starten sie ihren Computer und hören sie gleich ihre Lieblingsmusikstücke!                                
---------------------------------                                
cat -n /usr/local/bin/zufallsgenerator                                
#!/bin/bash                                
A=`ls /home/ich/Musik/relax/ | wc -l`;                                
B=`echo $((1 + $RANDOM % $A))`                                
/usr/bin/xplayer /home/se/Musik/relax/$B                                 
# Die Variable B bekommt ein zufälliger Wert von 1 bis n (n - maximale Anzahl ihre Dateien (bzw. Musikstücke) im Verzeichnis "relax")                                
---------------------------------                                
PS: Wenn sie das Skript in ihre Startprogramme hinzufügen, dann startet ihre Lieblingsmusikstück von dem Verzeichnis /home/ich/Musik/relax/ und zwar in eine zufällige Reihenfolge ;) und bei dem Start des Rechners hören sie gleich die Musik :)                                
PPS: Die Musikstücke sollen 1,2,3, ...n heißen.                  
-----------------

ubuntu cronjob funktioniert nicht ...

ubuntu: als normale user (kein root) funktioniert mein cronjob nicht und zwar:

crontab -e:                  
00 10 * * * ifconfig>/tmp/ifconfig_info                  
-----------

Ubuntu Cronjob Funktioniert Nicht ...

in dem fall ist es  ratsam absoluter  pfad zu nutzen: anstatt  ifconfig   -  /sbin/ifconfig

der cronjob wird dann so definiert:

00 10 * * * /sbin/ifconfig > /tmp/ifconfig_info

------------------

noch bessere lösung wäre es ein bash-skript  schreiben (z.B "schreib_mein_ifconfig"), das skript ausführbar machen (chmod 755 schreib_mein_ifconfig) und erst dann als cronjob definieren

----------------------------------

cat schreib_mein_ifconfig

​#!/bin/bash

/sbin/ifconfig > /tmp/ifconfig_info

----------------------------------

PS. WICHTIG:

​das skript muss auch mit dem absoluten pfad in der crontab eingetragen werden:

​crontab -e:

00 10 * * *  ​​/home/user/schreib_mein_ifconfig                  
-------------------

drupal: artikel-problem ...

Die Aufgabe: ein Artikel NICHT auf der Startseite publizieren.

Bis jetzt habe ich keine Lösung gefunden!

Hilfe!                  
------------------

hallo, man redet über

hallo, man redet über "Taxonomie" , "Vokabular" und "Begriffe" ,,,

ich habe neue seite erstellt, dann über taxonomie neuer vokabular und  begriffe zugewiesen ...

das hat nicht funktioniert

:-(                  
---------------------                  
motion server

hallo,  motion-server funktioniert, aber  die bilder von der webcam werden nicht gespeichert, obwohl ich target definiert habe:

target_dir /home/motion/motion                  
-----------------

##################

HIer ist ein "Muster" von /etc/motion/motion.conf :

---------------------

daemon on

setup_mode off

log_file /var/log/motion/motion.log

log_level 6

target_dir /var/lib/motion

videodevice /dev/video0

width 640

height 480

framerate 15

text_left CAMERA1

text_right %Y-%m-%d\n%T-%q

emulate_motion off

threshold 1500

despeckle_filter EedDl

minimum_motion_frames 1

event_gap 60

pre_capture 3

post_capture 0

picture_output on

picture_filename %Y%m%d%H%M%S-%q

movie_output on

movie_max_time 60

movie_quality 45

movie_codec mkv

movie_filename %t-%v-%Y%m%d%H%M%S

webcontrol_port 8080

webcontrol_localhost on

webcontrol_parms 0

stream_port 8081

stream_localhost off

In der Zeile "stream_localhost off" sollte tatsächlich "off" sein (es klingt erstmal ein wenig unlogisch, aber es muß so sein um Webzugriff zu gewerleisten - http://192.xxx.xxx.xxx:8081).

--------------------------------------

##################

motion server

hallo,

es muss die datei /etc/motion/motion.conf editiert werden und zwar:

bei ihnen (höchstwahrscheinlich) der parameter output_normal off es ist auch default-mäßig so. setzen sie der ob. gen. parameter auf on:

output_normal on

vorsicht!  falls vor der kamera viel los ist, wird das verzeichnis (target_dir) immer grösser!

target_dir /home/motion/

sie sollen das verzeichnis entweder manuell (ab und an) leeren oder per skript über den cronjob                  
--------------------                  
motion server/ bash-scripting ...

was bash-scripting betrifft, hier ist ein kleines beispiel:

vi /usr/local/bin/script/script_mv_50                  
------------------------------                  
#!/bin/bash                  
#### variablen definition #########                  
A=`du  /home/motion/motion|awk '{print $1}'`                  
###### falls das verzeichnis groesser als 5000 KB (5 MB) ist, loesch die erste 50 dateien (bilder) #########                  
if [[ $A -gt 5000 ]]                  
then                  
cd /home/motion/motion                  
mv `ls /home/motion/motion | head -50` /externe_festplatte;                  
else :                  
fi                  
------------------------------                  
das skript tut folgendes: die erste 50 dateien werden auf externe festplatte gemoved, sobald die größe des verzeichnisses grösser als 5000 KB ist.                  
um den vorgang zu automatisieren, kann das skript in crontab eingetragen werden. damit das skript mit 10 -minütigen rhythmus sich wiederholt, wird die folgende schreibweise benutzt:

crontab -e                  
*/10 * * * * /usr/local/bin/script/script_mv_50                  
---------------------                  
motion server - bash-scripting ...

es ergibt einen sinn die bilder (dateien) zu taren (einen tar-archiv zu erstellen) und dann  extern zu sichern, falls an dem  objekt viel los ist und sie das objekt nicht nur permanent beobachten möchten, sondern auch bilder speichern.                  
sie können, natürlich gleich das tar-archiv über das netz übertragen:

#!/bin/bash                  
#### variablen definition anfang #########                  
datum=`date +"%d"``date +%"m"``date +"%y"`                  
#### variablen definition ende #########                  
tar -czf - /home/motion/  | ssh ferner-rechner  "cat > /home/$datum-objekt_monitoring_bilder.tgz"

dank der "datum-variable" können die bild-archive später leicht nach datum einordnen.

in dem bereich bash-scripting  lässt es sich grenzenlos  experimentieren, z.b.:

 #!/bin/bash                  
#### variablen definition anfang #########                  
A=`ls  /home/motion/motion | wc -l`                  
#### variablen definition ende #########

### falls die anzahl der bilder ändert sich, dann tu das und das ####                  
if [[ $A -ne 0 ]]                  
then                  
           echo "ALARM"                  
else                      
           echo "alles OK"                  
fi

anstatt echo "ALARM"  können sie an sich selbst eine email senden (falls am linux rechner ein SSMTP-email-programm installiert ist) .... etc. pp.  ...........                  
-------------                  
bash-scripting ... rsync

man kann auch das synchronisation programm rsync (gleichzeitig ein netzwerkprotokoll) nutzen um die dateien über das netz sicher zu übertragen.                  
in dem fall wird das script so aussehen:

#!/bin/bash                  
rsync -av --delete -e ssh /home/motion/  user@ferner-rechner:/home/monitoring

ps. damit das skript einwandfrei funktioniert, müsste die passwortabfrage zwischen zwei rechnern (bzw. usern) unterdrückt werden.                  
wie das gemacht wird, ist ein anderes thema.                  
---------------                  
Das Skript "zufallsgenerator": Starten sie ihren Computer und hören sie gleich ihre Lieblingsmusikstücke!                  
---------------------------------                  
cat -n /usr/local/bin/zufallsgenerator

#!/bin/bash                  
A=`ls /home/ich/Musik/relax/ | wc -l`;                  
B=`echo $((1 + $RANDOM % $A))`                  
/usr/bin/xplayer /home/ich/Musik/relax/$B

# Die Variable B bekommt ein zufälliger Wert von 1 bis A (A - maximale Anzahl ihre Dateien (bzw. Musikstücke) im Verzeichnis "relax")                  
---------------------------------                  
PS: Wenn sie das Skript in ihre Startprogramme hinzufügen, dann startet ihre Lieblingsmusikstück von dem Verzeichnis /home/ich/Musik/relax/ und zwar in eine zufällige Reihenfolge ;) und bei dem Start des Rechners hören sie gleich die Musik :)                  
PPS: Die Musikstücke sollen 1, 2, 3, ... A heißen (also natürliche Zahl), weil $RANDOM akzeptiert nur natürliche Zahlen (Ganzzahl) und das wäre ein "Problem" (in Anführungszeichen), weil es ist nicht wirklich ein Problem sondern eine Aufgabe.                  
Die Aufgabe ist: Wie der String-Dateiname (z.B.) "relaxmusik.mp4" wandle ich in eine Ganzzahl um?                  
..................                  
Hier ist die Lösung (Here is the solution):                  
RANDOM under bash accepts (unfortunately) only numeric numbers                  
The contents of the directory "/home/iam/musik"                  
ls /home/se/music/                  
relaxmusik.mp4                  
rockmusic.mp4                  
jazz.mp4                  
My task was: define file names numerically as follows:                  
the name "relaxmusik.mp4" should be "1"                  
the name "rockmusic.mp4" should be "2"                  
etc. pp.                  
Here is the solution:                  
I create the script "solution":                  
cat solution                  
#!/bin/bash                  
A="mv"                  
B=`ls /home/iam/musik | wc -l`                  
ls /home/iam/musik > /tmp/name-of-files                  
i=1                  
while [ $i -le $B ]                  
do                  
echo $A $i                  
i=`expr $i + 1`                  
done                  
The script "solution" does the following:                  
the output of the script is:                  
mv 1                  
mv 2                  
mv 3                  
and the file "/tmp/name-of-files" is generated.                  
Its content is:                  
relaxmusik.mp4                  
rockmusic.mp4                  
jazz.mp4                  
The output of the script "solution" will be redirected to the file /tmp/mv-number: ./solution > /tmp/mv-number                  
also cat /tmp/mv-number is:                  
mv 1                  
mv 2                  
mv 3                  
Now I use the command "paste" and "awk":                  
paste /tmp/mv-number /tmp/name-of-files | awk '{print $1, $3, $2}'                  
And ... I get the correct output:                  
mv relaxmusik.mp4 1                  
mv rockmusic.mp4 2                  
mv jazz.mp4 3                  
and the content of my directory "/home/iam/musik" is now:                  
ls /home/iam/musik                  
1                  
2                  
3                  
finished! -> now i can start random music playback under bash!                  
PS. I would be happy for your better suggestions :)                  
------------------

ein skript "nachts_jeder_stunde"

#!/bin/bash                  
A=`ls /var/lib/motion/| wc -l`;                  
D=`date +"%d"``date +%"m"``date +"%y"`                  
E=`date | awk '{print $4}' | sed s/\:/-/g`                  
I=$D-$E                  
echo $I                  
cd /tmp/MOTION-ALARM/;                  
mkdir $D-$E                  
sleep 10                  
B=`ls /var/lib/motion/| wc -l`;

C=$[B-A]                  
echo $C

if [ $C -ne 0 ];

then

date > /tmp/MOTION-ALARM/$D-$E/datum-alarm                  
echo "ALARM"                  
echo "Info über motin-server" | sudo mail -s "Jemand ist in der Wohnung" xxxxx@gmail.com                  
else

echo "alles ruhig"

fi

############# Erklärung #############                  
Ich lasse das Skript über die Nacht jeder Stunde laufen von 01:10 bis 05:10 Uhr.                  
Ganz klar: Differenz zwischen zwei Variablen B und A sollte gleich 0 sein. Also Variable C=$[B-A]                  
gleich 0 - es gibt keine Bewegungen in der Wohnung - in der Wohnung ist dunkel!                  
Wenn das nicht der Fall sein sollte, dann (eindeutig): Jemand ist in der Wohnung! (Licht an, etc. pp.)                  
:(                  
-------------

Das Skript speedtest (bzw. speedtest-cli)

Das (war) ist ein Python-Skript mit 1508 Zeilen von Matt Martz. Das Skript hat auf einmal nicht mehr funktioniert:                  
./speedtest                  
Retrieving speedtest.net configuration...                  
Traceback (most recent call last):                  
File "./speedtest", line 1508, in                  
main()                  
File "./speedtest", line 1498, in main                  
shell()                  
File "./speedtest", line 1401, in shell                  
speedtest = Speedtest()                  
File "./speedtest", line 743, in __init__                  
self.get_config()                  
File "./speedtest", line 799, in get_config                  
map(int, server_config['ignoreids'].split(','))                  
#################                  
Und es ist sehr bedauerlich gewesen. Vor kurzem habe ich mein Linux Mint upgedated und dann "speedtest-cli" installiert:                  
# sudo apt install speedtest-cli                  
erneutinstalliert. Jetzt funktioniert es wieder :)                  
# sudo /usr/bin/speedtest-cli                  
Retrieving speedtest.net configuration...                  
Testing from Dein Provider (XXX.XXX.XXX.XXX)...                  
Retrieving speedtest.net server list...                  
Selecting best server based on ping...                  
Hosted by 31173 Services AB (Frankfurt) [23.59 km]: 8.044 ms                  
Testing download speed................................................................................                  
Download: 49.93 Mbit/s                  
Testing upload speed......................................................................................................                  
Upload: 11.19 Mbit/s

If "speedtest-cli" don't work, then take "speedtest-cli --secure" - then it will work                  
---------------------------                  
boot-images auflisten

1) ls -1s /boot                  
2) dpkg -l 'linux-[ihs]*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\([-0-9]*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'                  
-------------------------

raspberry pi Grafische Konsole auf deinem PC starten

ssh -X pi@192.168.1.2 lxpanel                  
------------------------------

vls aus Kommandozeile: Das Kommando nvlc

nvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_1.m3u                  
# damit hören sie "hrinfo" - Livestream von HR-Info                  
###########                  
pi@raspberrypi:~ $ ps -ef | grep vlc | grep -v grep                  
pi 6212 1 9 23:15 ? 00:02:32 /usr/bin/vlc -I dummy http://metafiles.gl-systemhaus.de/hr/hrinfo_1.m3u                  
##############                  
*/1 * * * * /usr/local/bin/radio_hr-info                  
cat /usr/local/bin/radio_hr-info                  
#!/bin/bash                  
#/usr/bin/vlc http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u &                  
if [ `ps -ef | grep vlc | grep -v grep | wc -l` -ne 1 ]                  
then cvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_1.m3u &                  
else echo "ok"                  
fi                  
Es wird jeder Minute geprüft, ob Radio eingeschaltet ist. Falls nicht, dann wird cvlc mit hrinfo_1.m3u gestartet:                  
cvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_1.m3u &

PS: Erfahrungsgemäß bricht die Verbindung zum Portal metafiles.gl-systemhaus.de/hr/hrinfo leider (aus ungeklärtem Grund) sporadisch ab. Ich habe eine "Krücke" gefunden. Im crontab habe ich folgendes Skript eingetragen:                  
*/1 * * * * /usr/local/bin/radio_hr-info                  
cat /usr/local/bin/radio_hr-info                  
#!/bin/bash                  
#/usr/bin/vlc http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u &                  
B=`date +"%d"``date +%"m"``date +"%y"`_`date | awk '{print $4}' | sed s/\:/-/g`;                  
if [ `ps -eLf | grep vlc | grep -v grep | wc -l` -ne 5 ]                  
then                  
ps -eLf | grep vlc | grep -v grep > /tmp/vlc_$B                  
kill -9 `ps -eLf | grep vlc | grep -v grep | awk '{print $2}'`;                  
cvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u &

else echo "ok"                  
fi                  
---------                  
Das Skript prüft, ob Prozesse von vlc laufen. Die Stückzahl der Prozessen sollte 5 sein. Falls das nicht der Fall sein sollte, werden die Prozesse gekillt und mit dem Kommando: cvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u &                  
wird die Musikausgabe erneut gestartet - und es funktioniert ;)                  
---------------

break unter bashing

#!/bin/bash                  
i=0

while [[ $i -lt 10 ]]                  
do                  
echo "Number: $i"                  
((i++))                  
if [[ $i -eq 5 ]]; then                  
break                  
fi                  
done                  
------------------

continue unter bashing

#!/bin/bash                  
i=0

while [[ $i -lt 5 ]]; do                  
((i++))                  
if [[ "$i" == '2' ]]; then                  
continue                  
fi                  
echo "Number: $i"                  
done                  
---------------------

Radio aus Konsole hören

# cvlc http://metafiles.gl-systemhaus.de/hr/hrinfo_2.m3u                  
-------------------

Online-Radio

Das Problem: Online-Radio bricht ab und zu ab (der Ton verschwindet).                  
D.h., dass Prozess-Zahl ändert sich.                  
Normalerweise die Zahl der vlc-Prozesse gleich 6:

A=`ps -AT | grep vlc | awk '{print $2}' | wc -l`                  
echo $A                  
6                  
------------------------------------                  
#!/bin/bash

# Variablendefinizion

A=`ps -AT | grep vlc | awk '{print $2}' | wc -l`

if [ $A -eq 6 ];

then

echo "OK";

else

# Falls die Zahl der Prozesse nicht equivalent 6, dann sollen die "Reste" des vlc-Prozess gekillt werden

kill `ps -AT | grep vlc | awk '{print $2}'`;

cvlc http://xxxxxxxxxxxxhrinfo_2.m3u &

fi                  
----------------

11 November, 2022 - 12:42

selaw2                  
Umgebung nach wlan-Geräte scannen

# sudo iwlist wlan0 scan | grep ESSID                  
----------------

  •  


пример скрипта, где линукс с системой наблюдения посылает емайл

An example where system sends a mail:

#!/bin/bash                
#### variablen definition anfang #########                
A=`ls  /home/motion/motion | wc -l`                
#### variablen definition ende #########

### falls die anzahl der bilder ändert sich, dann tu das und das ####                
if [[ $A -ne 0 ]]                
then                
           echo "тревога" | sudo mail -s "motionserver-контроль за объектом"  test@test.de                
else                    
           echo "alles OK"                
fi

------------

Das Skript sendet Mail an die test@test.de im Falle, wenn die Zahl der Webcam-Bilder (jpg) ändert sich.

PS. Vorausgesetzt wird das Paket "mailutils" vorinstalliert.                
-------------

bash-скрипт optimiert Eure Fotos.                
------------------------------

#!/bin/bash                
mkdir /tmp/OPT;                
for Y in `ls`;do convert  $Y  -resize 1200x900  $Y-opt.jpg ; mv *opt* /tmp/OPT; done;                
------------------------------                
Nach dem Skript werden die Fotos der Größe  4896х3672 px (oder noch größer) optimiert in Fotos                 
der Größe A x B (in unserem Fall 1280х960 px) und werden ins Verzeichnis "/tmp/OPT" geschoben. Die Originalfotos, bleiben in dem Verzeichnis "images". Die Größe der Optimirung  ist freiwählbar  (z. B. 1280х960):

A=4896/3,825

A=1280 px

B=3672/3,825

B=960 px                
----------------

Wenn die Fotos verschieden Größe haben und befinden sich im  "XY":

# convert image.jpg -resize 50% image_new.jpg

Die  %-Zahl  wählen sie selbst. In dem Baispiel ist die Zahl 50 - d. h., dass die Größe halbiert wird.                
------------------------                
Hier ist ein Beispiel von der GIF-Animation:

# convert -delay 120 -loop 0 *.jpg GIF-Santa.gif                
# cd my_dir                
# convert -delay 120 -loop 0 *.jpg GIF-Santa.gif

Quelle: linux-magazine (http://www.linux-magazine.com/Online/Blogs/Productivity-Sauce/Create-Animated-GIFs-with-ImageMagick)                
-----------------

pdf-file compress

To reduce a pdf-file (pdf-file compression):

1) the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf $1.pdf

You can write that as a script for example:  "compress_pdf"

#!/bin/bash                
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf  $1

and then execute:

./compress_pdf  your_original_file.pdf

as a result you get the following in the directory where you are:

your_small_file.pdf

------------

2) to give the command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}your_small_file.pdf orig_file.pdf

-----------------------

As a result: your original file "orig.pdf" will be your_small_file.pdf

For example:

orig.pdf      - 13,4 MB

your_small_file.pdf  -  519,4 KB

------------------------

3) gs -sDEVICE=pdfwrite -dCompatibilityLevel=4 -dNOPAUSE -dBATCH -r150 -sOutputFile=Zieldatei.pdf

And finally (if you have a lot of pdf-files), you can apply this script:

#!/bin/bash

PWD=pwd

cd $PWD

for A in `ls *pdf`; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=${1%\.pdf}optimiert/$A.pdf $A;done                
-------------

create user with bash

# useradd -m -d /home/iamauser -s /sbin/nologin  -G users  -c "i am a user" iamauser

user "iamauser" rename to jan

#usermod -l  jan  iamauser

.......................................

user jan new directory "/home/xyz"  to assign

# usermod -d /home/xyz -m jan                
.......................................

user jan lock

# usermod -L jan

.............

user jan group sudo attach

# usermod -aG sudo jan

delete user with home directory

# userdel -r User-Name

# userdel -r jan                
---------------------                
big file spliting and then "assemble"

# ls -la big_file

-rw-rw-r--   1 user users  187603950   Jun 14 10:13 big_file

big_file = 179 MB

I would like to splitting this file, for example into 10 MB files.

splitting:

# split -b 10m big_file  little_file_

Result:

-rwxrwxrwx 1 user user 187603950  Jan 23  2018 big_file                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aa                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ab                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ac                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ad                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ae                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_af                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ag                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ah                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ai                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aj                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ak                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_al                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_am                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_an                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ao                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_ap                
-rw-rw-r-- 1 user user  10485760  Jan 23 11:32 litle_file_aq                
-rw-rw-r-- 1 user user   9346030  Jan 23 11:32 litle_file_ar

assemble:

cat little_file_* > big_file_result

ls -la big_file_result

-rwxrwxrwx 1 user user 187603950  Jan 23  2018 big_file_result                
--------------

kill user (kill bill ;-)

sudo pkill -9 -u bill                
pkill -9 -u bill                
pgrep -u bill                
ps -fp $(pgrep -d, -u bill)                
------------

Transfer the tar-archive via ssh to remote computer

#!/bin/bash                
#### variablen definition anfang #########                
datum=`date +"%d"``date +%"m"``date +"%y"`                
#### variablen definition ende #########                
tar -czf - /home/motion/  | ssh ferner-rechner  "cat > /home/$datum-bilder.tgz"

or in a line (without script)

# tar -cvf - /home/user123/ | ssh hostname  "cat > /tmp/user123.tar"                
--------------

show "pure" ip-address (as numeral)

# ifconfig | head -2 | tail -1 | awk -F: '{print $2}' | awk -F\  '{print $1}'

PS. Sometimes we are need (in scripts) only numeral number                
------------

kill all processes as root

you must be root!

# echo k > /proc/sysrq-trigger                
-------------

sound test: aplay

#  aplay /usr/share/sounds/alsa/Front_Center.wav                
----------

if cursor disappeared (is gone) (falls mauszeiger weg ist)

if cursor disappeared (is gone) - falls mauszeiger weg ist - если "пропал" курсор:

1) # gsettings set org.gnome.settings-daemon.plugins.cursor active false

---------------                
2) # sudo modprobe -r psmouse

# sudo modprobe psmouse                
---------------                
3)  # xdotool mousemove 100 100                
#####################

gnome console completely restarting:

# sudo service gdm restart

----------------------

show soundcard

# cat /proc/asound/cards                
###################                
show linux version

# lsb_release -a

# cat  /etc/issue                
------------------------

pdf files bring together (to merge)

We have three pdf files: 1.pdf, 2.pdf and 3.pdf and want to merge the files.

The solution is:

1)

#  gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=123.pdf 1.pdf 2.pdf 3.pdf

2)

# gs -q -dNOPAUSE -dPDFSETTINGS=/ebook -dSAFER -sDEVICE=pdfwrite -sOutputFile=123.pdf 1.pdf 2.pdf 3.pdf quit.ps                
----------------------

test if data transfer is done

The task: you would like the (big) file download or transmitted via network and once the action is done, get a "signal" (or message).

If the size of the file does not change anymore, then we can say that the transfer has gone completely (*):

vi transfer_completely:

while true                
do                
A=`ls -la /home/download/file | tail -1 | awk '{print $5}'`;                
sleep 10;                
B=`ls -la /home/download/file | tail -1 | awk '{print $5}'`;                
C=`expr $B - $A`;                
if [ $C -ne 0 ]                
then echo "data transfer is not finished yet";                
else echo "data transfer is done" # instead of a message, you can turn on a jazz tune

/usr/bin/totem  /home/user/musik/jazz.mp4                
date > /tmp/protokoll_data_transfer_1 && exit 0                
fi                
done

(*)

May be that the transmission has failed or broke off, then the size of the "transmission-file" remains unchanged too.                
You must  to compare your "transmission-file" with original file size.                
--------------------

enter programs in start routine (linux mint mate)

# gnome-session-properties

In this grafical application you can put in your desired programm (linux mint mate)                
------------------

Start the command (for example - scp) on remote computer

# su - user -c "scp user@server:/tmp/bla.txt  .;"

Transfer of the file bla.txt  from remote PC to local                
-------------------                
mkfs - create the file system

Create the filesystem:

# mkfs.ext4 -L "" /dev/sdb1

# mkfs.fat -F32 -v -I -n "" /dev/sdb1                
-------------------

remove old linux-images

# sudo dpkg -l | grep linux-image

# sudo apt-get remove --purge linux-image-3.2.0-54-genericXXXX                
---------------------                
change password (without passowrd input)

vi change_password

passwd  $1 << EOM                
$1                
$1                
EOM

-----------------------

call the command:

./change_password   bla-bla-bla

The result:

user "bla-bla-bla" has changed his password. The password is now too "bla-bla-bla"                
----------------------                
network_restart

sudo service networking restart

or                
sudo ifup -a

or                
sudo /etc/init.d/network restart

or                
sudo service network-manager restart

or                
sudo ifdown --exclude=lo -a && sudo ifup --exclude=lo -a

or                
ifconfig eth0 down && ifconfig eth0 up

or                
ifconfig eth0 down

or                
ifconfig eth0 up                
--------------


system-config-printer ( graphically for linux mint mate)

# system-config-printer                
------------------

Turn on remote PC - Send WOL Magic Packet

#  wakeonlan  00:00:00:00:00:00

..................

How Do I Verify That Remote Linux Server Supports Wake-on-LAN (WOL)?

1) BIOS -> Power Management -> “Wake On LAN”;

2) # ethtool -s eth0 wol g

3) # ethtool eth0

-----------                
I am looking for GNOME command ...

To find out what is the command under GNOME means (for example "gnome-session-properties"), then I do the following:

1) ps -ef > /tmp/ps_1

2) I call the gnome startup console graphically

3) ps -ef > /tmp/ps_2

4) diff /tmp/ps_1 /tmp/ps_2

in the output is the searched command! -> (for example "gnome-session-properties")!!!                
:-)

-------------

new hostname

sudo hostname_new -F /etc/hostname                
or                
sudo echo "hostname_new" > /etc/hostname

--------------------                
Иногда "спасает" только текстовая консоль (termianl - lifebelt)

Иногда "спасает" только текстовая консоль (она же терминал). И если вы находитесь в графической оболочке, а вам надо открыть терминал, то это весьма просто сделать, используя:                
1) комбинацию клавиш, нажав одновременно "Alt" и "F2";                
2) в открывшемся окошке прописать команду "xterm" или "gnome-terminal" или "mate-terminal", etc. pp.);                
3) если ни "xterm", ни "gnome-terminal", ни какие-либо другие команды не исполняются, то в линуксе всегда можно перейти из графической консоли в терминал, применяя комбинацию клавиш:

Strg + Alt + F1, Strg + Alt + F2, Strg + Alt + F3 итак до ... F6.

Возможен, конечно, и обратный процесс, т.е., из текстовой консоли в графическую оболочку:                
Strg + Alt + F7 и Strg + Alt + F8 - эти комбинации клавиш возвращают вас обратно в графическую консоль.

В последних версиях Linux Mint (17,18),   комбинации клавиш "Strg + Alt + F7" и "Strg + Alt + F8" зарезервированы для графических консолей.                
Вы можете даже работать одновременно под двумя пользовтельскими именами и менять ваши графические оболочки, переходя из одной в другую нажатием вышеперечисленных комбинаций клавиш.

if you have the (very-very) old computer with linux, then (very rarely) just the same system may hang                
:-(                
then rescue us - only the text console  (it’s a terminal):

Strg + Alt + F1, Strg + Alt + F2, Strg + Alt + F3 ... +F6  and then:

# echo k > /proc/sysrq-trigger                
----------------

"wireshark" - powerful network traffic analysis tool (Sniffer)

# sudo wireshark

"wireshark" (бывший "Ethereal") - ein mächtiges Netzwerk-Tool (Sniffer).                
 "sudo tcpdump -vvv"                 
# sudo tcpdump -vvv | grep "google"                
-----------------                
loop "while_schleife_i-le_10" (while-schleife)

# cat while_schleife_i-le_10

#!/bin/sh                
i=1                      # Set variable i to 1 (Variable i auf 1 setzen)                
while test $i -le 10    # While-Schleife, externes Kommando test i<=10                
do                
   echo "x=$i"              # externes Kommando echo, gibt i aus                
   i=`expr $i + 1`      # externes Kommando expr, Ausgabe von expr nach i                
done

------------ the output ------------

./while_schleife_i-le_10

x=1                
x=2                
x=3                
x=4                
x=5                
x=6                
x=7                
x=8                
x=9                
x=10                
-------------------------                
Windows-Users give name of files with blank spaces! :-(

Often windows-users give the name of file  with blank spaces such as in this example:                
"a b 1.jpg" or "c d 2.jpg" ....  etc. pp.

# ls

a b 1.jpg

c d 2.jpg

e f 3.jpg

... also with blank

:-(

"delete_blank_of_the_filename" - a script to remove the blank spaces:

# cat delete_blank_of_the_filename

#!/bin/bash

ls *jpg | awk '{print $3}' > /tmp/list_jpg_file_with_blank;

for A in `cat /tmp/list_jpg_file_with_blank`;

do mv *$A  $A;

done

Result:

# ls

1.jpg

2.jpg

3.jpg                
---------------

convert jpg files to pdf and put together

You convert jpg files to pdf and put together only with one-line-little command:

# convert *jpg  all_files_in_one.pdf

PS. You make sure the files are not too big.  If the jpg files are larger than 2 MB, then they first should be optimized:

# for A in `ls *.jpg`; do convert $A -resize 50% $A-new.jpg; done

Otherwise your "all_files.pdf"  file will be too big.

----------------------------                
$i + 1 While-Schleife (while-loop)

Variant 1: cat  loop_counter_increment_1

#!/bin/sh                
i=1                      # Variable i auf 1 setzen                
while test $i -le 5    # testen ob  i<=5                
do                
 echo "x=$i"              #  gibt i aus                
   i=`expr $i + 1`      # expr, Ausgabe von expr nach i                
done

the output after the script execution:

# ./loop_counter_increment_1

x=1                
x=2                
x=3                
x=4                
x=5

Variant 2:  cat  loop_counter_increment_2

#!/bin/bash                
i=0                                             # set variable i to 0                
while [ $i -le 5 ]                         # loop - test if variable a less than 5                
do                                                              
 echo $i                                     # output variable i                
 let i=$i+1                                # counter increment                
done

the output after the script execution:

#  ./loop_counter_increment

0                
1                
2                
3                
4                
5                
-------------------------#################-----------------

cd brennen

# sudo cdrecord speed=2 image.iso

------------------

# cat daten_cd_brennen                
#!/bin/bash                
echo "cd einlegen"                
echo "lesevorgang ........."                
dd if=/dev/cdrom of=/var/spool/mkisofs/cdromcopy_data.iso                
echo "rohling einlegen"                
/usr/bin/cdrecord -v -dev=0,0,0 -speed=12 -eject                
/var/spool/mkisofs/cdromcopy_data.iso                
echo "cd kopiert"                
rm /var/spool/mkisofs/cdromcopy_data.iso

------------------

cat musik_cd_brennen                
#!/bin/bash                
echo "audio-cdrom einlegen........"                
/usr/bin/cdda2wav -D 0,0,0 -O wav -B                
echo "rohling einlegen........"                
/usr/bin/cdrecord -v -dev=0,0,0 -useinfo -speed=12 -dao -eject -audio *.wav                
echo "cd ist gebrannt worden"

-------------------------#################-----------------

check sound on the terminal

check sound -  the simple method on the terminal (for Linux Mint):

# aplay /usr/share/sounds/alsa/Front_Center.wav

if you hear words "front senter", then everything is ok!

ALSA: Advanced Linux Sound Architecture

Check it if if ALSA recognized your sound card:                
# cat /proc/asound/cards                
output (for example):

0 [Intel          ]: HDA-Intel - HDA Intel                
                     HDA Intel at 0xfe6fc000 irq 26                
1 [VF0770         ]: USB-Audio - Live! Cam Sync HD VF0770                
                     Creative Technology Ltd. Live! Cam Sync HD VF0770 at usb-0000:00:1d.7-4, high s

if output say:

"no soundcards"

then:

# lspci | grep -i audio

output (for example):

# 00:1b.0 Audio device: Intel Corporation NM10/ICH7 Family High Definition Audio Controller (rev 01)

if your system does not provide any output,  then you have bad luck, respectively have you bad sound cards :-(                
-------------------------#################-----------------

If you have american keyboard

If you have American keyboard and want to change to others, then:

# sudo apt-get install console-data                
# sudo dpkg-reconfigure keyboard-configuration                
# sudo apt-get update

-------------------------#################-----------------

Protect file via zip with the password

Suppose you want to quickly send a "secret file" -  "crypto_test " to your linux partner. You can package the file via zip and protect it with the password "blah" (or whatever your choice).

1) You create from your file "crypto_test"  password protected ZIP archive "crypto_test.zip" :

# zip -9 -P blah  crypto_test.zip -r crypto_test

Sent crypto_test.zip via email (*)

Your linux partner extract the ZIP archive:                
# unzip -P blah -n crypto_test.zip -d .

(*) That password should say like her linux partner (preferably) by phone.

PS. In the terminal, of course, the password "blah" is visible (but only for you).

-------------------------#################-----------------                
# sudo iftop

# netstat -tapecn

the network 192.168.1.1-255 will be scanned and open ports of the computer is displayed:

# nmap -v -sT 192.168.1.1-255

output:

.......................                
Discovered open port 9102/tcp on 192.168.1.1                
Discovered open port 9100/tcp on 192.168.1.1                
Discovered open port 9101/tcp on 192.168.1.1                
Discovered open port 515/tcp on  192.168.1.1                
....................                
Nmap scan report for 192.168.1.1                
Host is up (0.00020s latency).                
Not shown: 990 closed ports                
PORT     STATE SERVICE                
21/tcp   open  ftp                
80/tcp   open  http                
139/tcp  open  netbios-ssn                
445/tcp  open  microsoft-ds                
515/tcp  open  printer                
-------------------------#################-----------------

lsblk - block device information

# lsblk

output:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT                
sda      8:0    0 465,8G  0 disk                
├─sda1   8:1    0    94M  0 part                
├─sda2   8:2    0   9,4G  0 part                
├─sda3   8:3    0  81,6G  0 part                
├─sda4   8:4    0     1K  0 part                
├─sda5   8:5    0     4G  0 part [SWAP]                
├─sda6   8:6    0 170,8G  0 part /                
├─sda7   8:7    0 114,9G  0 part                
└─sda8   8:8    0     1M  0 part                
sr0     11:0    1  1024M  0 rom                  
sr1     11:1    1  1024M  0 rom  

# sudo lsblk -o name,uuid,fstype,size,label,mountpoint

output:

NAME    UUID                                 FSTYPE            SIZE                LABEL                 MOUNTPOINT                
sda                                                                   465,8G                             
├─sda1                                                              94M                             
├─sda2                                                              9,4G                             
├─sda3 70B62D29B62xxxxx              ntfs               81,6G OS                          
├─sda4                                                               1K                             
├─sda5 4a079a11-6780-4f61-91da-xx  swap           4G                                                [SWAP]                
├─sda6 5ac28f8d-bd0d-46ae-9202-x    ext4           170,8G                                              /                
├─sda7 9429ab6b-a67a-4cab-9bfc-4e5 ext4           114,9G         vbox-vmware                
└─sda8 fa8079f7-e6fc-4673-a555-14cc ext4           1M                             
sr0                                                                   1024M                             
sr1                                                                   1024M            

-------------------------#################-----------------

Keep your system clean - the tool "bleachbit"

Clean Your System and Free Disk Space with help the good graphical tool  "bleachbit":

# bleachbit

PS.  I have entered the tool "bleachbit" in the startup routine my linux. The other way around: You could start the tool before shutting down your computer. This is useful for the system.  Try it !                
Unfortunately, when the tool starts, I would have to trigger it manually.

PPS. Before executing  bleachbit your applications (firefox, chrome, etc. pp.) should be closed.

-------------------------#################-----------------

inxi - info and analyze your system!

# inxi -Fs

or (with info about repository)

# inxi -pluFxxrm

PS. To get more information about the command                
do not forget:

# man inxi

-------------------------#################-----------------

Hardware Information with lshw

# lshw

or

# lshw > /tmp/hw_info

to read information:

# cat /tmp/hw_info

PS. To get more information about the command                
do not forget:

# man lshw                
-------------------------#################-----------------

monitoring of your computer

A set of commands to create good monitoring of the computer:

# top

# atop

# htop

# glances

# vmstat  - report virtual memory statistics every five seconds

# while true; do sleep 5; vmstat; done

The last comand  reported virtual memory statistics every five seconds

-------------------------#################-----------------


while true; do sleep X ....

It is understandable,  that with this construct

while true; do sleep X ....

can build any repeat loop with the time-interpolation X                
-------------------------#################-----------------

rename file A to file a (big letters in the small letters)

The script "rename_A_to_a"

# cat rename_A_to_a

#!/bin/bash

ls -la | awk ' { print $9 } ' > dateien_gross;                
tr '[A-Z]' '[a-z]' < dateien_gross > dateien _klein;                
paste dateien_gross  dateien _klein > dateien_gr_kl;                
sed 's/^/mv\ /' dateien_gr_kl  > dateien_mv_gr_kl;                
sed '1d' dateien_mv_gr_kl > dateien_mv_gr_kl_1;                
sed '1d' dateien_mv_gr_kl_1 > dateien_mv_gr_kl_2;                
sed '1d' dateien_mv_gr_kl_2 > _2 > dateien_mv_gr_kl_end;

chmod 755 dateien_mv_gr_kl_end;                
./dateien_mv_gr_kl_end ;                
rm dateien* ;                
-------------------------#################-----------------

incremental backup with rsync of the directory /home/user123

# rsync -av --delete -e ssh /home/user123  user123@server:/home/user123

The first process of the rsync takes a "long" time (depending on the size of the files in the directory /home/user123)                
Assumed, over time, the files change.                
With opton "rsync -av --delete ...." the tool makes transfers only the files that have been changed.                
That's why the transfer does not take that long.

------------                
or:                
# rsync --delete -av original/ backup/

-------------------------#################-----------------

NFS mount for SuSE

on the server:                
# rcnfsserver start

on the client:                
# rcnfs start

# mount                
192.168.x.x:/home/shares  on /home/shares_clinet type nfs (rw,addr=10.x.x.x)

-------------------------#################-----------------


Image erstellen und durch das Netz übertragen

dd if=/dev/hda1 | gzip -9 - | ssh user@192.168.0.100 "cat > /home/BENUTZER/image_hda1.img.gz"

-------------------------#################-----------------

compress, gzip, bzip2, etc. pp.

compress -d datei.Z                
gzip -d datei.gz                
gzip -d datei.tgz                
bzip2 -d datei.bz2                
tar -xvf datei.tar                
tar -zxvf datei.tar.z                
rpm -i datei.rpm

-------------------------#################-----------------

dd über das Netz

dd if=/dev/hda1 | ssh benutzer@192.168.2.101 "cat > /home/Benutzer/meinimage.img"

-------------------------#################-----------------

gzip, bzip2, tar, etc. pp.

compress -d datei.Z                
gzip -d datei.gz                
gzip -d datei.tgz                
bzip2 -d datei.bz2                
tar -xvf datei.tar                
tar -zxvf datei.tar.z                
rpm -i datei.rpm

-------------------------#################-----------------

mount nfs

mount -t nfs server:/tmp /home/user

-------------------------#################-----------------

Datei spliten und wieder zusammenführen

split -b 10m grosse_datei kleine_dat_                
#wieder zusammen kleben cat kleine_dat_* >grosse_datei

-------------------------#################-----------------

tcpdump ....

tcpdump | grep -i "192.168.1.2" | awk '{print $2}' | cut -d. -f1 | grep -v "truncated-ip"

-------------------------#################-----------------

mount -t smbfs ....

mount -t smbfs -o username=abc,password=abc //fileserver/X /mnt/Y/

mount.cifs  //fileserver/X  /mnt/Y/ -o username=userxyz

smbmount //fileserver/user_1  /mnt/user_2/ -o username=userxyz

-------------------------#################-----------------

cd brennen

#!/bin/bash                
echo "audio-cdrom einlegen........"                
/usr/bin/cdda2wav -D 0,0,0 -O wav -B                
echo "rohling einlegen........"                
/usr/bin/cdrecord -v -dev=0,0,0 -useinfo -speed=12 -dao -eject -audio *.wav                
echo "cd ist gebrannt worden"                
-------------------------#################-----------------

netstat ...

netstat -tpan -- even

-------------------------#################-----------------

Zeit umstellen

hwclock --set --date="1/16/20 17:12:05"

hwclock --hctosys                
-------------------------#################-----------------                
nmap -> network-scanner

# sudo nmap -v -sT 1.2.3.4-255

# sudo nmap -PE -sn -oG - 192.162.1.1/24

# sudo nmap -sP -oG - 192.168.1.1/24

# sudo nmap -sS -F 192.168.0.1

# nmap -sV -Pn -p0- --reason --stats-every 60s 192.168.0.1

-------------------------#################-----------------

pdf-dateien zusammenfügen

pdfsam-console -f 1.pdf -f 2.pdf -f 3.pdf -f 4.pdf -o ./18022020.pdf concat

-------------------------#################-----------------

pdf datei verschlüsseln per pdftk

pdftk  BLA.pdf output BLA-crypt.pdf owner_pw parol_1 user_pw parol_2  allow Printing

-------------------------#################-----------------


split and cat (Dateien teilen und zusammenfügen)

du -h pushkin.mp4                
496M    pushkin.mp4

Um die Datei "pushkin.mp4" auzuspliten:

split -b 100M pushkin.mp4 split-pushkin.mp4

 

ls -la split-pushkin.mp4*                
-rw-r--r-- 1 ivan ivan 104857600 Apr  7 17:35 split-pushkin.mp4aa                
-rw-r--r-- 1 ivan ivan 104857600 Apr  7 17:36 split-pushkin.mp4ab                
-rw-r--r-- 1 ivan ivan 104857600 Apr  7 17:36 split-pushkin.mp4ac                
-rw-r--r-- 1 ivan ivan 104857600 Apr  7 17:36 split-pushkin.mp4ad                
-rw-r--r-- 1 ivan ivan 100092133 Apr  7 17:36 split-pushkin.mp4ae

du -h split-pushkin.mp4*                
101M    split-pushkin.mp4aa                
101M    split-pushkin.mp4ab                
101M    split-pushkin.mp4ac                
101M    split-pushkin.mp4ad                
96M    split-pushkin.mp4ae

 

Dateien split-pushkin.mp4a* zusammenfügen:

cat split-pushkin.mp4a*  >  pushkin.mp4

Es dauert 8 Secunden

:-)                
-------------------------#################-----------------

Wie wird ein gutes Passwort unter Befehlskonsole generiert

cat /dev/urandom  | tr -dc '[:alnum:][:punct:]' | head -c 12;echo

6o*?/bU2/uGz

cat /dev/urandom  | tr -dc '[:alnum:][:punct:]' | head -c 12;echo

kVsi~y&kM_$=

etc. pp.

-------------------------#################-----------------

shutdown -h +15 - Das System wird in 15 Min. heruntergefahren

sudo shutdown -h +15

Das Herunterfahren des Linux-Rechner in 15 Min.

-------------------------#################-----------------

alle Prozesse killen

echo k > /proc/sysrq-trigger

-------------------------#################-----------------


“restart” the touchpad driver ...

sudo /etc/init.d/hotplug restart                
-------------------------#################-----------------                
kill user ; kill bill

# sudo pkill -9 -u username

pgrep -u username < - > To list all users pids                
fuser -m /dev/sdb1                
kill xxxx                
-------------------------#################-----------------

image von bootmenü entfernen

sudo apt-get remove --purge paket1 paket2 paket3 (etc.pp.)                
dpkg -l | egrep linux-\(image\|headers\)-2.*-generic

-------------------------#################-----------------                
Zertifikate erneut installieren

sudo apt-get install --reinstall ca-certificates                
-------------------------#################-----------------


crypto-file system erstellen

I.

1. apt-get install cryptsetup hashalot                
2. mkfs.ext3 /dev/mapper/$CRYPTODEVICE                
3. cryptsetup -y -c aes-cbc-essiv:sha256 create crypt_250314   /dev/sda3                
4. mount /dev/mapper/$CRYPTODEVICE $MOUNT

----------------------

II.

Täglicher Gebrauch                
Trage deine Cryptopartition in /etc/crypttab ein, bspw:

   # target_device  source_device  key_file  options                
   $CRYPTODEVICE      /dev/$DEVICE     none        cipher=aes-cbc-essiv:sha256

   Trage in /etc/fstab das Device (/dev/mapper/$CRYPTODEVICE $MOUNT) mit deinen Dateisystemoptionen ein.

   /etc/init.d/cryptdisks kuemmert sich um die Initialisierung beim Booten. Bei Falscheingabe, kannst du nach dem login mit

   /etc/init.d/cryptdisks start

-------------------

III.

sudo apt-get install cryptsetup hashalot                
cryptsetup -y -c aes-cbc-essiv:sha256 create crypt_250314   /dev/sda3                
sudo cryptsetup -y -c aes-cbc-essiv:sha256 create crypt_250314   /dev/sda3                
mkfs.ext4 /dev/mapper/crypt_250314                
sudo mkfs.ext4 /dev/mapper/crypt_250314                

mount /dev/mapper/crypt_250314 /mnt/crypto/                
sudo mount /dev/mapper/crypt_250314 /mnt/crypto/                
-------------------------#################-----------------

dd: image uber das Netz ...

dd if=/dev/hda1 | gzip -9 - | ssh user@192.168.0.100 "cat > /home/BENUTZER/image_hda1.img.gz"

-------------------------#################-----------------

wheezy-raspbian.img auf micro sd karte

sudo dd if=/home/sd-karte/micro-sd.img of=/dev/mmcblk0                
sudo dd bs=1M if=wheezy-raspbian.img  of=/dev/mmcblk0

-------------------------#################-----------------

file bla.pdf aus der Konsole direkt ausdrucken

lp -d  Lexmark-E232  /home/bill/bla.pdf

-------------------------#################-----------------

schleife i=$[$i+1];

i=1;                
while [ $i -le $a ]; do                
echo $i;                
i=$[$i+1];                
done

-------------------------#################-----------------

fp reparieren

sudo e2fsck -fn /dev/sda1                
sudo e2fsck -p <device file>                
sudo e4defrag /home/user/directory/                
sudo e4defrag /dev/sda5

................

sudo dumpe2fs DEVICE                
-------------------------#################-----------------

grafische konsole stoppen

sudo service lightdm stop

sudo service gdm stop

-------------------------#################-----------------

sudo vi /etc/default/grub

1) sudo   vi  /etc/default/grub                
------------------------------                
die boot reihenfolge ändern:                
cat /etc/default/grub                
# If you change this file, run 'update-grub' afterwards to update                
# /boot/grub/grub.cfg.                
# For full documentation of the options in this file, see:                
#   info -f grub -n 'Simple configuration'

#0 oder 1 oder 2 etc. pp.                
----------->>> GRUB_DEFAULT=0 <<<<------------                
#GRUB_HIDDEN_TIMEOUT=0                
GRUB_HIDDEN_TIMEOUT_QUIET=true                
GRUB_TIMEOUT=10                
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`                
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"                
GRUB_CMDLINE_LINUX=""

# Uncomment to enable BadRAM filtering, modify to suit your needs                
# This works with Linux (no patch required) and with any kernel that obtains                
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)                
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"

# Uncomment to disable graphical terminal (grub-pc only)                
#GRUB_TERMINAL=console

# The resolution used on graphical terminal                
# note that you can use only modes which your graphic card supports via VBE                
# you can see them in real GRUB with the command `vbeinfo'                
#GRUB_GFXMODE=640x480

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux                
#GRUB_DISABLE_LINUX_UUID=true

# Uncomment to disable generation of recovery mode menu entries                
#GRUB_DISABLE_RECOVERY="true"

# Uncomment to get a beep at grub start                
#GRUB_INIT_TUNE="480 440 1"                
------------------------------                
2) sudo update-grub

-------------------------#################-----------------

sudo apt-key add

wget -O- http://deb.opera.com/archive.key | sudo apt-key add -

-------------------------#################-----------------

inxi

inxi -v7 -c 0                
inxi -Fs                
inxi -Fxx -fr                  
inxi -rfv7                
inxi -v 8

-------------------------#################-----------------


iptables

sudo iptables -A INPUT -s 1.2.3.4/15  -j DROP                
-------------------------#################-----------------

mate-control-center

mate-control-center


-------------------------#################-----------------

Befehle unter ubuntu

sudo update-manager -d                
-------------------------#################-----------------                
sudo apt-get install -f                
sudo apt-get dist-upgrade                
sudo apt-get install --reinstall ca-certificates                
sudo apt-get install ubuntu-restricted-extras

-------------------------#################-----------------

Benutzer "else" in die Gruppe sudo aufnehmen

usermod -aG sudo else

-------------------------#################-----------------


Version Abfrage

1) lsb_release -a

2) cat /etc/issue                
              
-------------------------#################-----------------

Schleife i=$i+1

#!/bin/bash                
i=0                
while [ $i -le 10 ]                
do                
 echo $i                
 let i=$i+1                
done

-------------------------#################-----------------


restart window-menager -a

xfwm4                
-------------------------#################-----------------

falls das verzeichnis groesser als 10 MB ist, loesch die erste

#!/bin/bash                
#### variablen definition #########                
A=`du  /var/lib/motion/ |awk '{print $1}'`                
#B=`expr $A`                
###### falls das verzeichnis groesser als 20 MB ist, loesch die erste 100 dateien #########                
if [[ $A -gt 10000 ]]                
then                
cd /var/lib/motion/;                   
rm `ls /var/lib/motion/ | head -100`;                
else :                
fi

-------------------------#################-----------------

bash - if else statement ...

   eq = equal                   <->  Gleichheit                
   ne = not equal             <->  Ungleichheit                
   le = lesser or equal      <-> kleiner oder gleich                
   lt = lesser than            <-> kleiner als                
   ge = greater or equal  <-> größer oder gleich                
   gt = greater than         <-> größer als

---------------

Ein kleines Skript:

#!/bin/bash                
while true                
do sleep 10                
  if [ `who | grep -v tty1 | wc -l` -ge 1 ]                
  then who  > jemand_ist_am_rechner; date >> jemand_ist_am_rechner                
  else echo ok                
  fi                
done

Hier wird es Datei "jemand_ist_am_rechner" generiert:

cat jemand_ist_am_rechner

pi       tty1          2020-01-30 05:20                
pi       pts/0        2020-05-14 09:00 (xxx.xxx.xxx.xxx) <- IP-Adresse von fremden Rechner                
Do 14. Mai 20:28:06 CEST 2020

-------------------------#################-----------------


if test oder if [ xxxx ]

-r Dateiname                
   Die Datei Dateiname existiert und ist lesbar                
-w Dateiname                
   Die Datei Dateiname existiert und ist beschreibbar                
-x Dateiname                
   Die Datei Dateiname existiert und ist ausführbar                
-d Dateiname                
   Die Datei Dateiname existiert und ist ein Verzeichnis                
-s Dateiname                
   Die Datei Dateiname existiert und ist nicht leer                
-b Dateiname                
   Die Datei Dateiname existiert und ist ein blockorientiertes Gerät                
-c Dateiname                
   Die Datei Dateiname existiert und ist ein zeichenorientiertes Gerät                
-g Dateiname                
   Die Datei Dateiname existiert und das SGID-Bit ist gesetzt                
-k Dateiname                
   Die Datei Dateiname existiert und das Sticky-Bit ist gesetzt                
-u Dateiname                
   Die Datei Dateiname existiert und das SUID-Bit ist gesetzt                
-p Dateiname                
   Die Datei Dateiname existiert und ist ein Named Pipe                
-e Dateiname                
   Die Datei Dateiname existiert                
-f Dateiname                
   Die Datei Dateiname existiert und ist eine reguläre Datei                
-L Dateiname                
   Die Datei Dateiname existiert und ist ein symbolischer Link                
-S Dateiname                
   Die Datei Dateiname existiert und ist ein Socket                
-O Dateiname                
   Die Datei Dateiname existiert und ist Eigentum des Anwenders, unter dessen UID das test-Programm gerade läuft                
-G Dateiname                
   Die Datei Dateiname existiert und gehört zu der Gruppe, zu der der User gehört, unter dessen UID das test-Programm gerade läuft                
Datei1 -nt Datei2                
-------------------------#################-----------------

netstat - gutes Netz-Monitoring-Tool

#!/bin/bash                
A=`netstat -an  | grep 8081`                
while true                
do sleep 60                
       if [ `netstat -an  | grep 8081 | wc -l` -gt 1 ]                
       then date >> bla; echo $A >> bla                
       else echo "OK"                
       fi                
done

------------

Hier wird in die Datei "bla" reingeschrieben, sobald jemand im Browser über den Port 8081 eine (ihre) Adresse geöffnet hat.

-------------------------#################-----------------                
sudo raspi-config

sudo raspi-config

1 Change User Password Change password for the current user                                                                                              
2 Network Options      Configure network settings                                                                                                         
3 Boot Options         Configure options for start-up                                                                                                    
4 Localisation Options Set up language and regional settings to match your location                                                                      
5 Interfacing Options  Configure connections to peripherals                                                                                               
6 Overclock            Configure overclocking for your Pi                                                                                                 
7 Advanced Options     Configure advanced settings                                                                                                        
8 Update               Update this tool to the latest version                                                                                             
9 About raspi-config   Information about this configuration tool                                                 
-------------------------#################-----------------

Das mächtige tool "find"

# find . type -size +50000000c -print                
oder                
# find . -type f -size +50000000c -print

PS: Die zwei Befehle sind identisch                
--------------                
alle Dateien im aktuellen Verzeichnis finden, die größe als 50 MB sind

-------------------------#################-----------------


Drucker HP Laserjet 1018 unter Linux (Mint 20) installieren

Baim Anschliessen wird der Drucker HP Laserjet 1018 automatisch installiert, druckt aber NICHT!                
:-(                
Das Kommando:                
hp-setup -i -g                
unter der Konsole ausführen und die Fragen beantworten.                
Dann wird der Drucker vollfunktionsfähig!                
Viel Spass                
;-)                
https://answers.launchpad.net/hplip/+question/645912

PS: Unter LInux Mint 20 brauchen sie nicht (mehr) "hplip" (HP Linux Imaging and Printing System) zu installieren                
Also das Kommando "sudo apt-get install hplip" ist überflüssig, weil hplip ist schon default-mäßig vorinstalliert.                
-------------------------#################-----------------

Linux mint update, upgrade ...

sudo apt update                
sudo apt upgrade                
apt list --upgradable                
sudo apt autoremove -f

-------------------------#################-----------------

sudo efibootmgr - die Bootrehenfolge ändern ...

Am Konsole führen Sie folgendes Kommando aus:

# sudo efibootmgr

Die Ausgabe kommt (Beispielweise) in der Form:

BootCurrent: 0000                
Timeout: 1 seconds                
BootOrder: 0000,0005,0006,0004,0001,0003,0002,0007,0008                
Boot0000* ubuntu                
Boot0001* Windows Boot Manager                
Boot0002* UEFI:CD/DVD Drive                
Boot0003* Generic Usb Device                
Boot0004* CD/DVD Device                
Boot0005* UEFI: PXE IPv4 Intel(R) Ethernet Connection (11) I219-V                
Boot0006* UEFI: PXE IPv6 Intel(R) Ethernet Connection (11) I219-V                
Boot0007* UEFI:Removable Device                
Boot0008* UEFI:Network Device                
----------                
"BootCurrent: 0000" - enspricht "Boot0000* ubuntu"                
Linux Mint verwendet "ubuntu" als seinen EFI-Startnamen.                
"Boot0000* ubuntu" - das bedeutet, dass Linux Mint startet zuerst (es wird auch so gewünscht).                
----------                
Falls bei euch anders ist, dann muss man das Kommando                
sudo efibootmgr --bootorder XXXX,YYYY                
(wobei XXXX und YYYY die Startoptionen der Betriebssysteme sind, die Sie starten möchten).                
Z.B. sudo efibootmgr --bootorder 0001 - für Windows-Start, etc. pp.

-------------------------#################-----------------

refresh-keys

# sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com

-------------------------#################-----------------

Fehlende Schlüssel importieren:

# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXXXXxxxx

-------------------------#################-----------------

Das Skrip "guten_morgen" ;)

##############

cat -n /usr/local/bin/guten_morgen:


#!/bin/bash

A=`ls /home/ich/Musik/relax/ | wc -l`;

B=`echo $((1 + $RANDOM % $A))`;

/usr/bin/xplayer /home/se/Musik/relax/$B


##############

PS.  Das Skript startet Musikplayer und die Musikstücke (falls sie die Variable RANDOM nutzen, dann bekommen sie ihre Musikstücke in eine Zufällige Reihenfolge.

Enjoy!                
#########                
Variable RANDOM unter bash arbeitet mit Ziffern. Aber Gewöhnlicherweise  Namen der Dateien sind Strings.                
Wir sollen Strings durch Zahlen ersetzen.  Hier ist die Lösung:                
Usually the filenames are strings. For example:                
ls /home/se/music/                
relaxmusik.mp4                
rockmusic.mp4                
jazz.mp4                
------------------                
My task would be to convert the character string to a number(just via a script.):                
mv relaxmusik.mp4 1                
mv rockmusik.mp4 2                
mv jazz.mp4 3                
etc. pp.                
I am on the (this) way:                
#!/bin/bash                
ls /home/iam/music/ > /tmp/bla-A                
cat -n /tmp/bla-A | awk '{print $1}'> /tmp/bla-B                
paste /tmp/bla-A /tmp/bla-B > /tmp/bla-C                
------                
the result: # cat /tmp/bla-C                
relaxmusik.mp4 1                
rockmusik.mp4 2                
jazz.mp4 3                
- two columns: name as character string and number (numeral).                
I need just first column with "mv":                
mv relaxmusik.mp4 1                
mv rockmusik.mp4 2                
mv jazz.mp4 3

-------------------------#################-----------------

Jemand Fremder am Computer

Angenommen, Sie sind am computer an der Konsole ein mal angemeldet (nur Sie:                
#who | wc -l                
1                
Und es muss auch so bleiben. Sie Möchten den Rechner quasi überwachen und Sie möchten alarmiert werden, sobald jemand Fremder am Computer ist.

Hier ist ein Skript "fremder":                
cat fremder                
#!/bin/bash                
date > nachricht                
echo "Alarm" >> nachricht                
while true                
do sleep 3                
# hier wird überprüft, ob jemand (ausser Ihnen) an der Konsole ist                
if [ `who | wc -l` -gt 1 ]                
then                
echo sendmail -f test@test.com < nachricht && break                
fi                
done                
PS: Natürlich muss zuerst am Linux-Computer das "mailutils"-Paket installiert worden sein.                
# sudo apt install mailutils

-------------------------#################-----------------

Crontab mit vi editieren

# sudo VISUAL=vi crontab -e

######## manchmal funktionieren cronjobs nicht: Bei mir was so, dass als root sind die cron-jobs nicht gelaufen. Ich habe als normale User die crontab-Tebelle editiert, dann sind die cronjobs einwandfrei gelaufen.

-------------------------#################-----------------


if Schleife

eq = equal = Gleichheit                
ne = not equal = Ungleichheit                
le = lesser or equal = kleiner oder gleich                
ge = greater or equal = größer oder gleich                
gt = greater than = größer als                
-------------------------#################-----------------


tar-archive erstellen

#!/bin/bash                
B=`date +"%d"``date +%"m"``date +"%y"`                
D=`date | awk '{print $4}' | sed s/\:/-/g`                
tar cfzv /home/pi/MOTION_getart/$B-$D-archiv.tar /var/lib/motion/                
chmod 755 /home/pi/MOTION_getart/*archiv.tar                
-------------------------#################-----------------

Mail aus der Konsole senden

# echo "Info über motin-server" | sudo mail -s "motin-server_test123" bla@bla.de

-------------------------#################-----------------

Link unter Konsole erstellen ...

ln -s datei link1

-------------------------#################-----------------

crontab restart (status, start, stop)

# sudo service cron status                
# sudo service cron restart                
# sudo service cron start                
# sudo service cron stop

-------------------------#################-----------------


Alle Mails, die angehängte Dateien haben, die größer als 10 MB

gmail-Mails finden, die angehängte Dateien haben, die größer als 10 MB sind                
In der Suchleiste des Mailsprogammes folgende Text schreiben:

has:attachment larger:10m                
-------------------------#################-----------------

du -h . --max-depth=1

# du -h . --max-depth=1                
Z.B. im Verzeichnis ViberDownloads (cd ~/.ViberPC/)                
68K ./PTT                
32K ./Temporary                
2,1M ./PublicAccountMedia                
1,3G .                
Na ja, 1,3 G - ist das nicht ein bisschen zu viel?                
;)                
Weg mit dem alten Viber-Schrott!                
:)                
-------------------------#################-----------------


Tor - "The Onion Routing"

Die Installation unter Linux Mint 20 Ulyana verläuft problemlos und dauert ein paar Minuten:                
1) sudo apt-get install torbrowser-launcher # installation des tor-browser                
2) /usr/bin/torbrowser-launcher # wird tor browser gestartet                
-------------------------#################-----------------

jpg to pdf

If Error # sudo convert *.jpg bla.pdf                
convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408                
Do it:                
Open /etc/ImageMagick-6/policy.xml with your favorite text editor, find the line and replace "none" by "read|write"

-------------------------#################-----------------

Ein Paket deinstallieren

# apt-get --purge remove "paket-name"

-------------------------#################-----------------

iw - show / manipulate wireless devices and their configuration

# iw list                
Wiphy phy0                
max # scan SSIDs: 4                
max scan IEs length: 2243 bytes                
max # sched scan SSIDs: 4                
max # match sets: 0                
max # scan plans: 1                
max scan plan interval: -1                
max scan plan iterations: 0                
Retry short limit: 7                
Retry long limit: 4                
Coverage class: 0 (up to 0m)                
Device supports T-DLS.                
Supported Ciphers:                
* WEP40 (00-0f-ac:1)                
* WEP104 (00-0f-ac:5)                
* TKIP (00-0f-ac:2)                
* CCMP-128 (00-0f-ac:4)                
* CCMP-256 (00-0f-ac:10)                
* GCMP-128 (00-0f-ac:8)                
* GCMP-256 (00-0f-ac:9)                
* CMAC (00-0f-ac:6)                
* CMAC-256 (00-0f-ac:13)                
* GMAC-128 (00-0f-ac:11)                
* GMAC-256 (00-0f-ac:12)                
................

-------------------------#################-----------------


nmcli - command-line tool for controlling NetworkManager

# nmcli con                
NAME UUID TYPE DEVICE                
Kabelgebundene Verbindung 1 xxxx-728d-3d1b-xxxx-xxxxx ethernet eno1                
FRITZ!Box ABC                
-------------------------#################-----------------

Abfrage lshw und iw list

# sudo lshw -c memory                
# sudo lshw -businfo                
# iw list

-------------------------#################-----------------

Netzwerk-Monitoring

1) wireshark; (sudo apt-get install wireshark)                
2) etherape; (sudo apt-get install etherape)                
3) ethstatus -i eth0; (sudo apt-get install ethstatus)                
4) bmon; (sudo apt-get install bmon)

-------------------------#################-----------------

systemctl -t service - > alle installierte Dienste in tab. Form

# systemctl -t service

UNIT LOAD ACTIVE SUB DESCRIPTION                
---------------------------------------------------------------------------------------------                
accounts-daemon.service loaded active running Accounts Service                
acpid.service loaded active running ACPI event daemon                
alsa-restore.service loaded active exited Save/Restore Sound Card State                
apparmor.service loaded active exited Load AppArmor profiles

-------------------------#################-------------------------------------                
Info: Wie lange der Bootvorgang dauert:

# systemd-analyze               
Startup finished in 4.188s (kernel) + 10.219s (userspace) = 14.407s                
graphical.target reached after 10.209s in userspace               
 Noch ausführliche listet das Kommando "systemd-analyze blame" den Startvorgang auf.

# systemd-analyze blame

5.682s NetworkManager-wait-online.service                                  
2.414s sendmail.service                                                    
1.343s snap-core-14447.mount                                               
1.335s snap-gtk\x2dcommon\x2dthemes-1534.mount                             
1.273s snap-ubports\x2dinstaller-435.mount                                 
1.232s mysql.service                                                       
1.180s snap-ubports\x2dinstaller-418.mount                                 
1.109s nfs-server.service                                                  
1.106s snap-snapd-17950.mount                                              
988ms snap-gnome\x2d3\x2d38\x2d2004-115.mount                             
948ms snap-speedtest\x2dcli-30.mount                                      
915ms dev-loop1.device                                                    
889ms dev-loop3.device                                                    
877ms snap-core18-2667.mount                                              
874ms snap-core20-1778.mount                     
............................ etc. pp. ............................

-------------------------#################------------------------------------- 

Beim Start des Rechners macht das System analyse sowohl des System selbst als auch alle angeschlossene Geräte. Diese Systemmeldungen können wir dann -mittels des Befehls "dmesg"- anschauen.             
# dmesg -T             
oder einfach              
# dmesg

-------------------------#################------------------------------------- 

apt-Befehle:

# apt update -> SW-Pakete aktualisieren            
# apt install [Paketname] -> Programm-Paket installieren            
# apt remove [Paketname] -> Programm-Paket deinstallieren            
# apt purge [Paketname] -> [Paketname] komplett löschen            
# apt autoremove -> Überflüßige Pakete löschen (nach der Deinstallation)            
# apt upgrade [Paketname] -> komplettes System aktualisieren             
# apt full-upgrade -> komlette Aktualisierung des System (die ältere Pakete werden dabei gelöscht)            
# apt-cach search [Paketname] -> sucht nach Paketnamen und Beschreibungen

Der Befehl dpkg            
# dpkg -l -> listet alle installierte Pakete aus

-------------------------#################------------------------------------- 

# sudo /sbin/blockdev --getalignoff

Das Kommando gibt den Versatz (Offset) der abgefragten Partition aus, und wenn es eine Null zurückgibt, liegt diese perfekt auf den Speicherzellen. Nur wenn eine andere Zahl erscheint, passt das Partitions-Alignment nicht zur SSD.

-------------------------#################------------------------------------- 

# sudo fstrim -v -a 

Trimmen per „Batched Discard“ ist sehr einfach.

-------------------------#################------------------------------------- 

Linux Mint auf neuste Stand bringen:

# sudo apt list --upgradable && sudo apt update && sudo apt dist-upgrade

Nach dem Befehl, habe ich folgende Meldung bekommen:

"Aktualisierung für 6 Pakete verfügbar. Führen Sie »apt list --upgradable« aus, um sie anzuzeigen"

Damit # sudo apt list --upgradable  wurden mir die Pakete angezeigt:

Zurückgehaltene pakete:

libpulse-mainloop-glib0 libpulse0 libpulsedsp pulseaudio pulseaudio-module-bluetooth pulseaudio-utils

die ich mit installiert habe:

# sudo apt install libpulse-mainloop-glib0 libpulse0 libpulsedsp pulseaudio pulseaudio-module-bluetooth pulseaudio-utils

Letzendlich, wenn sie noch mal den Befehl:

sudo apt update && sudo apt dist-upgrade 

abgeben, dann sollen sie folgendes bekommen:
Auflistung… Fertig
OK:1 http://mirror.23media.com/ubuntu jammy InRelease
Ign:2 http://linux-mint.froonix.org vera InRelease                                 
OK:3 http://mirror.23media.com/ubuntu jammy-updates InRelease                      
OK:4 http://mirror.23media.com/ubuntu jammy-backports InRelease                    
OK:5 http://linux-mint.froonix.org vera Release                                    
OK:6 http://security.ubuntu.com/ubuntu jammy-security InRelease                    
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Statusinformationen werden eingelesen… Fertig
Alle Pakete sind aktuell.
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Statusinformationen werden eingelesen… Fertig
Paketaktualisierung (Upgrade) wird berechnet… Fertig
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

-------------------

# do-release-upgrade

cat -n /etc/update-manager/release-upgrades
    1    # Default behavior for the release upgrader.
    2    
    3    [DEFAULT]
    4    # Default prompting and upgrade behavior, valid options:
    5    #
    6    #  never  - Never check for, or allow upgrading to, a new release.
    7    #  normal - Check to see if a new release is available.  If more than one new
    8    #           release is found, the release upgrader will attempt to upgrade to
    9    #           the supported release that immediately succeeds the
   10    #           currently-running release.
   11    #  lts    - Check to see if a new LTS release is available.  The upgrader
   12    #           will attempt to upgrade to the first LTS release available after
   13    #           the currently-running one.  Note that if this option is used and
   14    #           the currently-running release is not itself an LTS release the
   15    #           upgrader will assume prompt was meant to be normal.
   16    Prompt=normal
 ### oder ###

# sudo apt install ubuntu-release-upgrader-core

default

Prompt=lts

-------------------

Das Kommando:

# sudo apt --fix-broken install 

zeigt die gebrochene Installationspakete an

 

Skype installieren unter Linux - kein Problem aber dann, kurz nach dem Start, könntest du folgende Meldung bekommen:

W: https://repo.skype.com/deb/dists/stable/InRelease: Schlüssel ist im veralteten Schlüsselbund trusted.gpg gespeichert (/etc/apt/trusted.gpg), siehe den Abschnitt MISSBILLIGUNG in apt-key(8) für Details.

Die Lösung wäre:
# wget -qO - https://repo.skype.com/data/SKYPE-GPG-KEY | sudo gpg --dearmor > skype-keyring.gpg
# sudo mv skype-keyring.gpg /etc/apt/trusted.gpg.d/
# sudo chown root:root /etc/apt/trusted.gpg.d/skype-keyring.gpg
# sudo chmod ugo+r,go-w /etc/apt/trusted.gpg.d/skype-keyring.gpg

########################################

Firefox: Probleme mit der automatischen Updates: 

"Updates von Ihrem System-Administrator deaktiviert"

Die Lösung:

cd /usr/lib/firefox/distribution

sudo vi policies.json

{
   "policies":
   {
       "DisableAppUpdate": true
   }

}

Kommentieren sie die Zeile   "DisableAppUpdate": true   aus:

{
   "policies":
   {
#       "DisableAppUpdate": true
   }

}

Fertig!

;)

################

Wenn du nach Leistung deines Gerätes fragst, dann versuchst du damit (eine simple Metode Leistung deines Gerätes zu messen):

time (i=0; while ((i < 9999999));do ((i++));done)

##############

 

 

Make script, not war!
Hoch lebe die Ukraine!
We Stand With Ukraine!