Linux - Snippets: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
 
(6 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
== Snippets ==
+
== Siehe auch ==
 +
[[Terminal und Konsole auf dem Mac]]
 +
== User und Rechte ==
 +
=== Als Superuser arbeiten ===
 +
sudo su
 +
oder
 +
sudo [kommando]
 +
 
 +
== Dateien ==
 +
[[Linux - tar]]
 
=== Downloads mit cURL ===
 
=== Downloads mit cURL ===
 
http://www.thegeekstuff.com/2012/04/curl-examples/
 
http://www.thegeekstuff.com/2012/04/curl-examples/
 
  
 
=== Dateien komprimieren mit gz ===
 
=== Dateien komprimieren mit gz ===
Zeile 22: Zeile 30:
  
 
  tar xfvz archiv.tar.gz
 
  tar xfvz archiv.tar.gz
 +
 +
== Suchen und finden ==
 +
ps ax | grep ssh
 +
ps aux | grep mysql
 +
 +
ls -altr
 +
=== Lösche Ordner und Unterordner mit bestimmten Namen ===
 +
Nur leere Ordner:
 +
find . -type d -name myFolderName -exec rmdir {} \;
 +
 +
Use find for name "a" and execute rm to remove those named according to your wishes, as follows:
 +
find . -name a -exec rm -rf {} \;
 +
Test it first using ls to list:
 +
find . -name a -exec ls {} \;
 +
To ensure this only removes directories and not plain files, use the "-type d" arg (as suggested in the comments):
 +
find . -name a -type d -exec rm -rf {} \;
 +
The "{}" is a substitution for each file "a" found - the exec command is executed against each by substitution.
 +
 +
== Prozesse ==
 +
=== Top ===
 +
http://man.openbsd.org/top.1
 +
Prozesse auflisten
 +
top
 +
top [-1bCHIinqSu] [-d count] [-g string] [-o [-]field] [-p pid] [-s time] [-U [-]user] [number]
 +
 +
top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)
 +
Filter by commandname: top -p expects a comma separated list of pids so we use -d',' in pgrep. The -f flag in pgrep makes it match the command line instead of program name.
 +
top -u [user]
 +
==== Shortcuts für Top Interactive Mode ====
 +
<pre>
 +
 +
h | ?
 +
    Display a summary of the commands (help screen).
 +
^L
 +
    Redraw the screen.
 +
<space>
 +
    Update the screen.
 +
q
 +
    Quit top.
 +
 +
+
 +
    Reset any filters put in place by the ‘g’, ‘p’, and ‘u’ interactive commands, or their command line equivalents, or any process highlighting put in place by the ‘P’ interactive command.
 +
1
 +
    Toggle the display of per CPU or combined CPU statistics.
 +
C
 +
    Toggle the display of process command line arguments.
 +
d count
 +
    Show only count displays, then exit.
 +
e
 +
    Display a list of system errors (if any) generated by the last kill or renice command.
 +
g string
 +
    Display only processes that contain string in their command name. If displaying of arguments is enabled, the arguments are searched too. ‘g+’ shows all processes.
 +
H
 +
    Toggle the display of process threads.
 +
I | i
 +
    Toggle the display of idle processes.
 +
k [-sig] pid
 +
    Send signal -sig (TERM by default) to process pid. This acts similarly to the command kill(1).
 +
n|# count
 +
    Show count processes.
 +
o [-]field
 +
    Sort the process display area using the specified field as the primary key. The ‘-’ prefix reverses the order. Values are the same as for the -o flag, as detailed above.
 +
P pid
 +
    Highlight a specific process, selected by pid. ‘P+’ removes process highlighting.
 +
p pid
 +
    Show only the process pid. ‘p+’ shows all processes.
 +
r count pid
 +
    Change the priority (the nice) of a list of processes to count for process pid. This acts similarly to the command renice(8).
 +
S
 +
    Toggle the display of system processes.
 +
s time
 +
    Set the delay between screen updates to time seconds.
 +
u [-]user
 +
    Show only those processes owned by username or UID user. ‘u+’ shows processes belonging to all users. The ‘-’ prefix hides processes belonging to a single user.
 +
</pre>
  
 
== Skripte ==
 
== Skripte ==

Aktuelle Version vom 31. Januar 2020, 11:23 Uhr

Siehe auch[Bearbeiten]

Terminal und Konsole auf dem Mac

User und Rechte[Bearbeiten]

Als Superuser arbeiten[Bearbeiten]

sudo su

oder

sudo [kommando]

Dateien[Bearbeiten]

Linux - tar

Downloads mit cURL[Bearbeiten]

http://www.thegeekstuff.com/2012/04/curl-examples/

Dateien komprimieren mit gz[Bearbeiten]

Eine Datei komprimieren

gzip file

Ergbnis: file.gz

Datei dekomprimieren:

gunzip file

Dateien in einem komprimierten Archiv zusammenfassen:

tar cfvz archiv.tar.gz inhalt1 inhalt2

Ergebnis: archiv.tar.gz

Archiv dekomprimieren und auspacken:

tar xfvz archiv.tar.gz

Suchen und finden[Bearbeiten]

ps ax | grep ssh
ps aux | grep mysql
ls -altr

Lösche Ordner und Unterordner mit bestimmten Namen[Bearbeiten]

Nur leere Ordner:

find . -type d -name myFolderName -exec rmdir {} \;

Use find for name "a" and execute rm to remove those named according to your wishes, as follows:

find . -name a -exec rm -rf {} \;

Test it first using ls to list:

find . -name a -exec ls {} \;

To ensure this only removes directories and not plain files, use the "-type d" arg (as suggested in the comments):

find . -name a -type d -exec rm -rf {} \;

The "{}" is a substitution for each file "a" found - the exec command is executed against each by substitution.

Prozesse[Bearbeiten]

Top[Bearbeiten]

http://man.openbsd.org/top.1

Prozesse auflisten

top
top 	[-1bCHIinqSu] [-d count] [-g string] [-o [-]field] [-p pid] [-s time] [-U [-]user] [number]
top -c -p $(pgrep -d',' -f string_to_match_in_cmd_line)

Filter by commandname: top -p expects a comma separated list of pids so we use -d',' in pgrep. The -f flag in pgrep makes it match the command line instead of program name.

top -u [user]

Shortcuts für Top Interactive Mode[Bearbeiten]


h | ?
    Display a summary of the commands (help screen).
^L
    Redraw the screen.
<space>
    Update the screen.
q
    Quit top.

+
    Reset any filters put in place by the ‘g’, ‘p’, and ‘u’ interactive commands, or their command line equivalents, or any process highlighting put in place by the ‘P’ interactive command.
1
    Toggle the display of per CPU or combined CPU statistics.
C
    Toggle the display of process command line arguments.
d count
    Show only count displays, then exit.
e
    Display a list of system errors (if any) generated by the last kill or renice command.
g string
    Display only processes that contain string in their command name. If displaying of arguments is enabled, the arguments are searched too. ‘g+’ shows all processes.
H
    Toggle the display of process threads.
I | i
    Toggle the display of idle processes.
k [-sig] pid
    Send signal -sig (TERM by default) to process pid. This acts similarly to the command kill(1).
n|# count
    Show count processes.
o [-]field
    Sort the process display area using the specified field as the primary key. The ‘-’ prefix reverses the order. Values are the same as for the -o flag, as detailed above.
P pid
    Highlight a specific process, selected by pid. ‘P+’ removes process highlighting.
p pid
    Show only the process pid. ‘p+’ shows all processes.
r count pid
    Change the priority (the nice) of a list of processes to count for process pid. This acts similarly to the command renice(8).
S
    Toggle the display of system processes.
s time
    Set the delay between screen updates to time seconds.
u [-]user
    Show only those processes owned by username or UID user. ‘u+’ shows processes belonging to all users. The ‘-’ prefix hides processes belonging to a single user. 

Skripte[Bearbeiten]

Datenbank sichern[Bearbeiten]

#!/bin/bash

DATUM=`date +%d.%m.%Y_%a%H-%M`
MYSQLPATH=/usr/bin/
DBUSER=diensthandyadm
DBNAME=diensthandy
DBPASS=MeinPasswort
BACKUPDIR="/serv/www/diensthandy.dekra.com/bak/db"

# dump database
#/usr/bin/mysqldump --all-databases -u diensthandyadm -pMeinPasswort > $BACKUPDIR/"diensthandy_$DATUM.sql"
${MYSQLPATH}mysqldump $DBNAME -u $DBUSER -p${DBPASS} > ${BACKUPDIR}/${DBNAME}_${DATUM}.sql

/bin/gzip ${BACKUPDIR}/"${DBNAME}_${DATUM}.sql"

# delete older

find $BACKUPDIR -type f -mtime +4 -exec rm {} \;

Backup Skript[Bearbeiten]

#!/bin/bash
###############################################################################
# Skript legt ein Backup der aktuellen Dateien im webverzeichnis an 
# und holt sich eine neue Version vom Produktivserver
##############################################################################
datum=`date`
BACKUPDIR="/serv/www/diensthandy.dekra.com/bak"
WEBDIR="/serv/www/diensthandy.dekra.com/data"
ADMINMAIL="schlegel@geo-bit.de"
BETREFF="DEKRA Diensthandy -  Produktivserver Kopie"

# Webdateien verschieben/sichern (alte Kopie löschen)
#rm -rf $BACKUPDIR/data/*
#mv $WEBDIR/* $BACKUPDIR/data/
#echo "--- Webverzeichnis gesichert ---"

# Kopie von Produktivserver holen
# scp -r schlegel@212.9.188.227:/serv/www/diensthandy.dekra.de/data/* $WEBDIR/.
# echo "--- Kopie von Produktivserver geholt ---"

# Config-zurückspielen
cp $BACKUPDIR/data/includes/configure.php $WEBDIR/includes/
cp $BACKUPDIR/data/admin/includes/configure.php $WEBDIR/admin/includes/
echo "--- Konfigurationsdateien kopiert ---"

# Cache Verzeichnisse löschen
rm -rf $WEBDIR/cache/*
rm -rf $WEBDIR/templates_c/*
# Rechte anpassen

chmod 775 -R $WEBDIR/*
chmod 777 -R $WEBDIR/cache
chmod 777 -R $WEBDIR/templates_c
chmod 444 $WEBDIR/includes/configure.php
chmod 444 $WEBDIR/admin/includes/configure.php

echo "--- Rechte angepasst ---"