first commit
This commit is contained in:
commit
d47f1dc602
9 changed files with 1247 additions and 0 deletions
122
Code/Bash/Bash-Basics.md
Normal file
122
Code/Bash/Bash-Basics.md
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
# Bash scripting basics
|
||||||
|
|
||||||
|
Kommt immer zu begin eines neuen Scripts
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Berechtigung um ausgeführt zu werden
|
||||||
|
|
||||||
|
```
|
||||||
|
chmod +x FILENAME
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Description Numeric Comparison String Comparison
|
||||||
|
|
||||||
|
```
|
||||||
|
Shell comparison example: [ 100 -eq 50 ]; echo $? [ "GNU" = "UNIX" ]; echo $?
|
||||||
|
less than -lt <
|
||||||
|
greater than -gt >
|
||||||
|
equal -eq =
|
||||||
|
not equal -ne !=
|
||||||
|
less or equal -le N/A
|
||||||
|
greater or equal -ge N/A
|
||||||
|
boolean
|
||||||
|
true=0
|
||||||
|
false=1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
Operator Description
|
||||||
|
! EXPRESSION The EXPRESSION is false.
|
||||||
|
-n STRING The length of STRING is greater than zero.
|
||||||
|
-z STRING The lengh of STRING is zero (ie it is empty).
|
||||||
|
[ -a FILE ] True if FILE exists.
|
||||||
|
[ -b FILE ] True if FILE exists and is a block-special file.
|
||||||
|
[ -c FILE ] True if FILE exists and is a character-special file.
|
||||||
|
[ -d FILE ] True if FILE exists and is a directory.
|
||||||
|
[ -e FILE ] True if FILE exists.
|
||||||
|
[ -f FILE ] True if FILE exists and is a regular file.
|
||||||
|
[ -g FILE ] True if FILE exists and its SGID bit is set.
|
||||||
|
[ -h FILE ] True if FILE exists and is a symbolic link.
|
||||||
|
[ -k FILE ] True if FILE exists and its sticky bit is set.
|
||||||
|
[ -p FILE ] True if FILE exists and is a named pipe (FIFO).
|
||||||
|
[ -r FILE ] True if FILE exists and is readable.
|
||||||
|
[ -s FILE ] True if FILE exists and has a size greater than zero.
|
||||||
|
[ -t FD ] True if file descriptor FD is open and refers to a terminal.
|
||||||
|
[ -u FILE ] True if FILE exists and its SUID (set user ID) bit is set.
|
||||||
|
[ -w FILE ] True if FILE exists and is writable.
|
||||||
|
[ -x FILE ] True if FILE exists and is executable.
|
||||||
|
[ -O FILE ] True if FILE exists and is owned by the effective user ID.
|
||||||
|
[ -G FILE ] True if FILE exists and is owned by the effective group ID.
|
||||||
|
[ -L FILE ] True if FILE exists and is a symbolic link.
|
||||||
|
[ -N FILE ] True if FILE exists and has been modified since it was last read.
|
||||||
|
[ -S FILE ] True if FILE exists and is a socket.
|
||||||
|
STRING1 = STRING2 STRING1 is equal to STRING2
|
||||||
|
STRING1 != STRING2 STRING1 is not equal to STRING2
|
||||||
|
INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
|
||||||
|
INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
|
||||||
|
INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example if then else in bash
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
num_a=400
|
||||||
|
num_b=200
|
||||||
|
if [ $num_a -lt $num_b ]; then
|
||||||
|
echo "$num_a is less than $num_b!"
|
||||||
|
else
|
||||||
|
echo "$num_a is greater than $num_b!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## IF ELSE && CASE
|
||||||
|
|
||||||
|
```
|
||||||
|
if Perform a set of commands if a test is true.
|
||||||
|
else If the test is not true then perform a different set of commands.
|
||||||
|
elif If the previous test returned false then try this one.
|
||||||
|
&& Perform the and operation.
|
||||||
|
|| Perform the or operation.
|
||||||
|
case Choose a set of commands to execute depending on a string matching a particular pattern.
|
||||||
|
fi End of if
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Variabeln
|
||||||
|
|
||||||
|
```
|
||||||
|
name='Someone' -Nur Text kann man in einem String speichern.
|
||||||
|
username=$(whoami) -funktionen werden mit $() angegeben
|
||||||
|
day=$(date +%A) -parameter können ohne Probleme in die Klammer schreiben.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command Exec
|
||||||
|
|
||||||
|
der befehl kommt ohne syntax einfach auf eine leere zeile z.b.
|
||||||
|
|
||||||
|
```
|
||||||
|
fortune
|
||||||
|
cowsay hallo
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
ich kann die beiden commands aber auch zusammensetzen
|
||||||
|
|
||||||
|
```
|
||||||
|
fortune | cowsay
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## stderr stdout
|
||||||
|
|
||||||
|
The difference between stdout and stderr output is an essential concept as it allows us to a threat, that is, to redirect each output separately. The > notation is used to redirect stdout to a file whereas 2> notation is used to redirect stderr and &> is used to redirect both stdout and stderr. The cat command is used to display a content of any given file
|
13
Code/CPP/CPP-Basics.md
Normal file
13
Code/CPP/CPP-Basics.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Structure of a Program
|
||||||
|
|
||||||
|
Every C++ program must have a function named **main** (all lower case letters). When the program is run, the statements inside of _main_ are executed in sequential order.
|
||||||
|
|
||||||
|
```
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
std::cout << "Hello World!";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
35
Code/CPP/Visual-Studio-Settings.md
Normal file
35
Code/CPP/Visual-Studio-Settings.md
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# Visual Studio Dependencies
|
||||||
|
|
||||||
|
## Install dependencies
|
||||||
|
|
||||||
|
For developing C++ in Visual Studio 2022 on Windows 11 you have to install the _Desktop development with C++._ If you don't do this, the C++ capabilities will not be available.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## C++ Console Application
|
||||||
|
|
||||||
|
To create a C++ Console Application you have to create a new Project. In Visual Studio you select _Windows Desktop Wizard._ After naming the project the IDE opens the _Windows Desktop Project_ window. Make sure the Application type is on _Console Application (.exe)_ and that the _Precompiled Header_ option is unselected.
|
||||||
|
|
||||||
|
## Compiler Extensions
|
||||||
|
|
||||||
|
> **Best Practice**
|
||||||
|
>
|
||||||
|
> Disable compiler extensions to ensure your programs (and coding practice) remain compliant with C++ standards and will work on any System.
|
||||||
|
|
||||||
|
To do this you have to right click on your project name in the _Solution Explorer_ window, then choose _Properties_. First make sure the configuration is set to _All Configurations_. Then, click _C/C++ > Language tab,_ and set _Conformance mode _ to _Yes(/permissive-)._
|
||||||
|
|
||||||
|
## Warning and Error levels
|
||||||
|
|
||||||
|
> **Best Practice**
|
||||||
|
>
|
||||||
|
> Don't let warnings pile up. resolve them as you encounter them (as if they were errors). Otherwise a warning about a serious issue may be lost amongst warnings about non-serious issues.
|
||||||
|
|
||||||
|
You IDE can support you by handling the warnings. In the Solution Properties you can turn up your warning levels. To increase them, go to the _Properties_ of your solution and then you have to set for _All Configurations_ in _C/C++ > General _ then _Warning levels_ to _Level4 (/W4)_ and for more support the _Treat Warnings As Errors_ to _Yes (/WX)._
|
||||||
|
|
||||||
|
## Language standard
|
||||||
|
|
||||||
|
To select a language standard, open your solution properties, then open _C/C++ > Language._ Make sure the Configuration is set to _All Configurations._ From there, you can set the _C++ Language Standard_ to the version of C++ you wish to use.
|
||||||
|
|
||||||
|
> **Warning**
|
||||||
|
>
|
||||||
|
> With Visual Studio, you will need to reselect your language standard every time you create a new project.
|
89
Code/CSharp/Basics.md
Normal file
89
Code/CSharp/Basics.md
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# C# basics
|
||||||
|
|
||||||
|
## Dokumentation
|
||||||
|
|
||||||
|
```
|
||||||
|
/// <summary>
|
||||||
|
/// Was Macht diese Klasse / Methode / constante
|
||||||
|
///
|
||||||
|
/// Unten kommt immer der Name des Developers welcher diese class programmiert hat
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="NameDesParameters"></param>
|
||||||
|
/// <returns>Was wird mit return zurückgegeben</returns>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
if (Expression) Genau so auch bei While und for etc. { }
|
||||||
|
|
||||||
|
## Namespaceaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2
|
||||||
|
namespace NameDesNamespaces
|
||||||
|
{
|
||||||
|
1: Das ist immer gleich. einfach namespace
|
||||||
|
2: das ist der name des namespace dieser wird eigentlich durch die ordnerstrucktur erstellt
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Classaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4
|
||||||
|
public/privat partial/nichts class NameDerKlasse
|
||||||
|
{
|
||||||
|
1: Ist die class nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: Wenn partial geschrieben wird kann innerhalb des selben Namespace mehr zu der classe geaddet werden
|
||||||
|
wird eigentlich nur in grossen projeckten verwendet.
|
||||||
|
3: das keyword class ist immer gleich.
|
||||||
|
4: Der Klassen name dieser wird gross geschrieben wenn es eine public class sein soll.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## variablen einer class
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4
|
||||||
|
public/privat string/int VariablenName { get; set; }
|
||||||
|
1: Ist die variable nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: Type der variable.
|
||||||
|
3: Name der variable wenn gross dann public sonst klein für privat.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Constructor einer class
|
||||||
|
|
||||||
|
```
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
private string last;
|
||||||
|
private string first;
|
||||||
|
1 2 3
|
||||||
|
public Person(string lastName, string firstName)
|
||||||
|
{
|
||||||
|
last = lastName;
|
||||||
|
first = firstName;
|
||||||
|
}
|
||||||
|
1: public/privat um es öffentlich zu machen
|
||||||
|
2: Name der class ist immer gleich wie vom costructor
|
||||||
|
3: alle parameter welche von anfang an initalisiert werden sollen.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Funktionsaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4 5
|
||||||
|
public/privat static/nichts void/string/int Name(string/int Args)
|
||||||
|
{
|
||||||
|
1: Ist die funktion nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: muss diese funktion mit new initialisiert werden oder nicht
|
||||||
|
3: was wird aus der funktion returnt
|
||||||
|
4: Der Name der funktion klein bei privaten gross bei public
|
||||||
|
5: Die Args weilche Mitgegeben werden. immer mit dem type im vorfeld.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
255
Code/CSharp/Interface.md
Normal file
255
Code/CSharp/Interface.md
Normal file
|
@ -0,0 +1,255 @@
|
||||||
|
# C# basics
|
||||||
|
|
||||||
|
## Dokumentation
|
||||||
|
|
||||||
|
```
|
||||||
|
/// <summary>
|
||||||
|
/// Was Macht diese Klasse / Methode / constante
|
||||||
|
///
|
||||||
|
/// Unten kommt immer der Name des Developers welcher diese class programmiert hat
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="NameDesParameters"></param>
|
||||||
|
/// <returns>Was wird mit return zurückgegeben</returns>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
if (Expression) Genau so auch bei While und for etc. { }
|
||||||
|
|
||||||
|
## Namespaceaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2
|
||||||
|
namespace NameDesNamespaces
|
||||||
|
{
|
||||||
|
1: Das ist immer gleich. einfach namespace
|
||||||
|
2: das ist der name des namespace dieser wird eigentlich durch die ordnerstrucktur erstellt
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Classaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4
|
||||||
|
public/privat partial/nichts class NameDerKlasse
|
||||||
|
{
|
||||||
|
1: Ist die class nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: Wenn partial geschrieben wird kann innerhalb des selben Namespace mehr zu der classe geaddet werden
|
||||||
|
wird eigentlich nur in grossen projeckten verwendet.
|
||||||
|
3: das keyword class ist immer gleich.
|
||||||
|
4: Der Klassen name dieser wird gross geschrieben wenn es eine public class sein soll.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## variablen einer class
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4
|
||||||
|
public/privat string/int VariablenName { get; set; }
|
||||||
|
1: Ist die variable nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: Type der variable.
|
||||||
|
3: Name der variable wenn gross dann public sonst klein für privat.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Constructor einer class
|
||||||
|
|
||||||
|
```
|
||||||
|
public class Person
|
||||||
|
{
|
||||||
|
private string last;
|
||||||
|
private string first;
|
||||||
|
1 2 3
|
||||||
|
public Person(string lastName, string firstName)
|
||||||
|
{
|
||||||
|
last = lastName;Interface
|
||||||
|
=========
|
||||||
|
|
||||||
|
Ein Interface kann man sich vorstellen, wie ein Bauplan. Dieser wird meistens einer Mutterklasse vererbt.\
|
||||||
|
Es gibt diverse Gründe warum man ein Interface benutzt.
|
||||||
|
|
||||||
|
- Man kann ein Interface als Parameter Type einbauen.
|
||||||
|
- Man hat eine Verpflichtung alle Eigenschaften einzubauen in eine Klasse.
|
||||||
|
|
||||||
|
Schauen wir uns doch einmal an wie ein Interface aussehen kann.\
|
||||||
|
In diesem Beispiel gehen wir von einem Zoo mit Tieren aus und die Tiere haben dann Tochter Klassen welche die Gattung darstellen.
|
||||||
|
|
||||||
|
Interface erstellen
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Ein Interface wird mit dem Keyword interface erstellt und hat immer ein grosses I vor dem Namen.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Interfaces
|
||||||
|
{
|
||||||
|
interface IAnimal
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Das Interface wurde innerhalb des Interfaces Unterverzeichnis erstellt.
|
||||||
|
|
||||||
|
Wir bauen jetzt quasi einen Bauplan für die Animal Klasse.
|
||||||
|
|
||||||
|
Properties einbauen
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Im nächsten Schritt fügen wir die angeforderten Properties hinzu.
|
||||||
|
|
||||||
|
Beachte, dadurch das nicht jedes Prop ein set hat, kann dies später nicht geändert werden.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Interfaces
|
||||||
|
{
|
||||||
|
interface IAnimal
|
||||||
|
{
|
||||||
|
string name { get; set; }
|
||||||
|
string foodType { get; }
|
||||||
|
string habitat { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Wie du sehen kannst ist es nicht notwendig, das Keyword virtual zu verwenden. Es handelt sich ja auch nicht um eine Klasse sondern um ein Interface.
|
||||||
|
|
||||||
|
Methoden einbauen
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
Fügen wir doch jetzt noch einige Methoden ein.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Interfaces
|
||||||
|
{
|
||||||
|
interface IAnimal
|
||||||
|
{
|
||||||
|
string name { get; set; }
|
||||||
|
string foodType { get; }
|
||||||
|
string habitat { get; }
|
||||||
|
void MakeNoise();
|
||||||
|
void Eat();
|
||||||
|
void Move();
|
||||||
|
Image GetImage();
|
||||||
|
string GetARandomName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Wie du sehen kannst, haben die Methoden keine Funktionalität eingebaut. Wir geben lediglich an welchen Rückgabe Wert und welche Parameter verwendet werden müssen.
|
||||||
|
|
||||||
|
Klasse mit Interface
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
Jetzt können wir eine neue Klasse hinzufügen welche das Interface beinhaltet. Es wird gleich eingebunden wie eine Vererbung. Animal : IAnimal
|
||||||
|
|
||||||
|
Ignoriere erstmal das Keyword abstract. [Du findest hier mehr dazu.](/Code/CSharp/Keyword/abstract)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Animal : IAnimal
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Der Code wird so nicht kompilierbar sein. Das Interface zwingt dich dazu die Properties und Methoden einzubauen.
|
||||||
|
|
||||||
|
Fangen wir mit den Properties an.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Animal : IAnimal
|
||||||
|
{
|
||||||
|
public virtual string name { get; set; } = "animal";
|
||||||
|
public virtual string foodType { get; } = "Animalfood";
|
||||||
|
public virtual string habitat { get; } = "Cage";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Zu beachten ist, dass die Props genau so eingebunden werden, wie im Bauplan beschrieben. Achte dabei auf die get und set Keywords.
|
||||||
|
|
||||||
|
Jetzt fügen wir alle Methoden ein.
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Animal : IAnimal
|
||||||
|
{
|
||||||
|
public virtual string name { get; set; } = "animal";
|
||||||
|
public virtual string foodType { get; } = "Animalfood";
|
||||||
|
public virtual string habitat { get; } = "Cage";
|
||||||
|
|
||||||
|
public virtual void MakeNoise()
|
||||||
|
{
|
||||||
|
Debug.Write($"{this.name} makes a Noise:");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Eat()
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"The {this.GetType().Name} Named {this.name} Eats: {this.foodType}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Move()
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"The {this.GetType().Name} Moves around.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Image GetImage()
|
||||||
|
{
|
||||||
|
return AnimalsRes.Lion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetARandomName()
|
||||||
|
{
|
||||||
|
// Code für einen random Namen.
|
||||||
|
return "randomName"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Jetzt sollte der Code Kompilierbar sein.
|
||||||
|
first = firstName;
|
||||||
|
}
|
||||||
|
1: public/privat um es öffentlich zu machen
|
||||||
|
2: Name der class ist immer gleich wie vom costructor
|
||||||
|
3: alle parameter welche von anfang an initalisiert werden sollen.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Funktionsaufbau
|
||||||
|
|
||||||
|
```
|
||||||
|
1 2 3 4 5
|
||||||
|
public/privat static/nichts void/string/int Name(string/int Args)
|
||||||
|
{
|
||||||
|
1: Ist die funktion nur für diesen Namespace gedacht oder auch für auserhalb
|
||||||
|
2: muss diese funktion mit new initialisiert werden oder nicht
|
||||||
|
3: was wird aus der funktion returnt
|
||||||
|
4: Der Name der funktion klein bei privaten gross bei public
|
||||||
|
5: Die Args weilche Mitgegeben werden. immer mit dem type im vorfeld.
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
89
Code/CSharp/Vererbung-Heredity.md
Normal file
89
Code/CSharp/Vererbung-Heredity.md
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# Heredity
|
||||||
|
|
||||||
|
Die Vererbung ist wohl das mächtigste Tool für C#.\
|
||||||
|
Es bedeutet, dass man von Mutter klassen zu Tochter klassen alle Eigenschaften weitergeben kann.
|
||||||
|
|
||||||
|
In meinem Beispiel, werde ich dass aufzeigen anhand eines Zoo's mit Tieren und den Kategorien welche es da gibt.
|
||||||
|
|
||||||
|
## Mutter Klasse
|
||||||
|
|
||||||
|
Wir haben ein Tier, dieses kann ein Geräusch machen mit der Methode `MakeNoise()`.\
|
||||||
|
Wenn ich nun ein Säugetier erstellen will, macht dieses ja ein anderes Geräusch als ein Vogel.
|
||||||
|
|
||||||
|
Wichtig ist: Bei einer Mutter klasse schreiben wir immer da das Keyword `virtual` hin, wo wir die Möglichkeit haben wollen, in der Tochter klasse dies zu bearbeiten oder ganz zu verändern.
|
||||||
|
|
||||||
|
```
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Animal
|
||||||
|
{
|
||||||
|
public virtual string name { get; set; } = "animal";
|
||||||
|
public virtual string foodType { get; } = "Animalfood";
|
||||||
|
public virtual string habitat { get; } = "Cage";
|
||||||
|
|
||||||
|
public virtual void MakeNoise()
|
||||||
|
{
|
||||||
|
Debug.Write($"{this.name} makes a Noise: ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Wir lassen jetzt das Säugetier von Animal erben.\
|
||||||
|
Dies geht, indem wir nach dem Klassennamen die zu erbende Klasse nach einem : einfügen. Hier mit: `Mammal : Animal`
|
||||||
|
|
||||||
|
```
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Mammal : Animal
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Nun können wir einige der Properties und Methoden verändern bzw. überschreiben.\
|
||||||
|
Wir ändern `foodType` & `habitat` so wie die Methode `MakeNoise()`.\
|
||||||
|
Mit dem Keyword `override`.
|
||||||
|
|
||||||
|
```
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Mammal : Animal
|
||||||
|
{
|
||||||
|
public override string foodType => "Mammalfood";
|
||||||
|
public override string habitat => "Cage";
|
||||||
|
|
||||||
|
public override void MakeNoise()
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"{this.name} makes a Noise: Mammal Noise");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Wenn wir uns den Code der Methode `MakeNoise()` von Animal anschauen sehen wir, dass wir ein `Debug.Write` verwenden dies könnten wir weiterverwenden, mit `this.base()`
|
||||||
|
|
||||||
|
```
|
||||||
|
namespace Zoo.Animals
|
||||||
|
{
|
||||||
|
public abstract class Mammal : Animal
|
||||||
|
{
|
||||||
|
public override string foodType => "Mammalfood";
|
||||||
|
public override string habitat => "Cage";
|
||||||
|
|
||||||
|
public override void MakeNoise()
|
||||||
|
{
|
||||||
|
this.MakeNoise();
|
||||||
|
Debug.WriteLine("Mammal Noise");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Mit diesem Code wird erst die Methode `MakeNoise()` von Animal aufgerufen. Was dazu führt, dass in die Konsole `{this.name} makes a Noise: ` geschriben wird.\
|
||||||
|
Im nächsten Schritt wird mit `Debug.WriteLine("Mamal Noise")` Mamal Noise auf der gleichen Zeile ausgegeben und eine neue Zeile begonnen.
|
||||||
|
|
||||||
|
Die Ausgabe wird `{this.name} makes a Noise: Mamal Noise` sein.
|
||||||
|
|
||||||
|
Es sind 2 Wege zum gleichen Ziel.
|
88
Code/Powershell/Basics.md
Normal file
88
Code/Powershell/Basics.md
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
Basics (WIP)
|
||||||
|
============\
|
||||||
|
PowerShell ist eine Objekt-Orientierte Shell. Sie wurde entwickelt um die antike CommandPrompt abzulösen.\
|
||||||
|
Man kann alle CMD-Commands in PowerShell ausführen, um jedoch PowerShell-Commands in CMD auszuführen muss man:\
|
||||||
|
`powershell Get-ChildItem`\
|
||||||
|
PowerShell mit dem Command dem man ausführen möchte rufen.
|
||||||
|
|
||||||
|
**PowerShell ist Case-Insensitive** das heisst das auch Commands wie: `gEt-hElP GeT-lOcAlUsEr` problemlos ausgeführt werden können.\
|
||||||
|
Commands in PowerShell sind immer <Verb>-<Nomen>.
|
||||||
|
|
||||||
|
Hotkeys
|
||||||
|
-------\
|
||||||
|
`CTRL` + `L` sendet der Shell den Clear-Command
|
||||||
|
|
||||||
|
`↑↓` Erlaubt das durchsuchen der Command-History
|
||||||
|
|
||||||
|
`TAB` AutoComplete des aktuellen Commands oder `SHIFT` + `TAB` um durch mögliche AutoComplete's durchzusuchen.
|
||||||
|
|
||||||
|
`CTRL` + `ALT` + `SHIFT` + `?` Gibt eine Liste von allen Hotkeys im Terminal aus.
|
||||||
|
|
||||||
|
### Help\
|
||||||
|
|
||||||
|
Mit `Get-Help <command>` bekommt man Hilfe zu einem spezifischen Command.\
|
||||||
|
Diese Liste kann mit `Update-Help` aktualisiert werden.
|
||||||
|
|
||||||
|
## Getting Around
|
||||||
|
|
||||||
|
### Get-Location\
|
||||||
|
|
||||||
|
Um herauszufinden wo wir uns gerade befinden benutzen wir den Command: `Get-Location`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Get-ChildItem
|
||||||
|
|
||||||
|
Um Inhalte aus Ordner anzeigen zu lassen brauchen wir: `Get-ChildItem`\
|
||||||
|
Wir können uns Inhalte ausgeben die nicht im unserem aktuellen Ordner ist ausgeben: `Get-ChildItem <path-to-folder>`\
|
||||||
|
Dieser Command hat folgende Aliase: `gci`, `ls`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Set-Location
|
||||||
|
|
||||||
|
Um uns schliesslich in ein anderes Verzeichnis zu bewegen verwenden wir: `Set-Location <path-to-folder>`\
|
||||||
|
Dieser Command hat folgende Aliase: `cd`
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Clear-Host
|
||||||
|
|
||||||
|
Um das Terminal-Fenster aufzuräumen oder wieder leer zu machen benutzen wir: `Clear-Host`\
|
||||||
|
Dieser Command hat folgende Aliase: `clear`, `cls`
|
||||||
|
|
||||||
|
## User- & Group-Management
|
||||||
|
|
||||||
|
### Get-LocalUser
|
||||||
|
|
||||||
|
Mit dem Command: `Get-LocalUser` werden uns alle Lokale-Benutzer angezeigt
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### New-LocalUser
|
||||||
|
|
||||||
|
Um einen neuen Benutzer zu erstellen können wir: `New-LocalUser -Name "JLawrence" -NoPassword` brauchen.
|
||||||
|
|
||||||
|
\
|
||||||
|
Danach können wir eine Variable setzten: `$Password = Read-Host -AsSecureString`
|
||||||
|
|
||||||
|
Mit dem `$` sagen wir PowerShell das wir eine Variable erstellen.\
|
||||||
|
Der Command `Read-Host` sorgt dafür das PowerShell ein string entgegen nimmt.\
|
||||||
|
Schliesslich mit `-AsSecureString` können wir dafür sorgen das unsere Eingabe mit '\*' überdruckt wird.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Set-LocalUser
|
||||||
|
|
||||||
|
Um Benutzer zu bearbeiten verwenden wir: `Set-LocalUser`\
|
||||||
|
Um also dem erstellten Benutzer ein Password hinzuzufügen werden wir den Command `Set-LocalUser -Name JLawrence -Password $Password` verwenden.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Get-LocalGroup
|
||||||
|
|
||||||
|
`Get-LocalGroup` gibt uns alle lokale Benutzer im Terminal aus:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Next Adduser to local group
|
333
File-Share/Samba.md
Normal file
333
File-Share/Samba.md
Normal file
|
@ -0,0 +1,333 @@
|
||||||
|
# Samba cheat sheet (EN)
|
||||||
|
|
||||||
|
### Install dependencies for samba:
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt install samba
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config samba server
|
||||||
|
|
||||||
|
> Edit `/etc/samba/smb.conf`. There are a lot of options here. Here is a basic share configuration. Add it to the end of the file.
|
||||||
|
|
||||||
|
```
|
||||||
|
[myshare]
|
||||||
|
comment = This is my share
|
||||||
|
path = /path/to/share/directory
|
||||||
|
browseable = yes
|
||||||
|
read only = no
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Restart samba service
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl restart smbd
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
> To connect to your share, unless you are just using guest access, you need to set up Samba user accounts
|
||||||
|
|
||||||
|
```
|
||||||
|
smbpasswd -a {username [root, user]}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## home directories
|
||||||
|
|
||||||
|
> If home directories for individual users are set up on the server in the system folder /home/, all of them can be shared by a single entry in the [homes] section. The necessary settings for this are already prepared. To enable this collective sharing of all home directories, you just have to remove all semicolons ";" in front of the entries.
|
||||||
|
|
||||||
|
```
|
||||||
|
[homes]
|
||||||
|
comment = home directories
|
||||||
|
browseable = no
|
||||||
|
valid users = %S
|
||||||
|
writeable = yes
|
||||||
|
create mode = 0600
|
||||||
|
directory mode = 0700
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
> The home directories are shared under the name of the respective user, but not displayed on the network because of browseable = no. Because of valid users = %S only the user with the matching name has access; other users cannot see, read, or write to the share. Because of create mode = 0600 and directory mode = 0700, only the corresponding user has access rights to newly created files and folders, even on the server itself.
|
||||||
|
>
|
||||||
|
> The [homes] section is a considerable simplification compared to single shares, especially for systems with many users.
|
||||||
|
|
||||||
|
## Individual shares
|
||||||
|
|
||||||
|
Then the individual shares are entered. A share consists of the share name in square brackets - i.e. [example share] - and the options following it. The graphical interfaces to Samba also enter the shares here.
|
||||||
|
|
||||||
|
> Note: Often people forget that the access rights in the share and in the local file system must be correct. For example, if you allow guests to access a directory, the user nobody or the group nogroup must also have the corresponding local read/write permissions in the directory.
|
||||||
|
|
||||||
|
### **Example 1**
|
||||||
|
|
||||||
|
Example of a share that can only be accessed by logged-in users, who can only read but not write. The entries marked with (Default) correspond to the default settings. They are for explanation only and may be omitted:
|
||||||
|
|
||||||
|
```
|
||||||
|
[example1]
|
||||||
|
# path to directory
|
||||||
|
path = /path/to/data1
|
||||||
|
# comment to share
|
||||||
|
comment = test share 1
|
||||||
|
# share is active (default)
|
||||||
|
available = yes
|
||||||
|
# share is directly visible (default)
|
||||||
|
browseable = yes
|
||||||
|
# guests are not allowed to access the share (default)
|
||||||
|
guest ok = no
|
||||||
|
# Logged in users may read but not write (default).
|
||||||
|
writeable = no
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Example 2**
|
||||||
|
|
||||||
|
Example of a share that everyone - including guests - can access both read and write. Furthermore, the data is accessed locally with the user rights otto and the group rights users:
|
||||||
|
|
||||||
|
```
|
||||||
|
[example2]
|
||||||
|
# path to directory
|
||||||
|
path = /path/to/data2
|
||||||
|
# Guests are also allowed to access the share
|
||||||
|
guest ok = yes
|
||||||
|
# Logged in users are also allowed to write.
|
||||||
|
writeable = yes
|
||||||
|
# share is directly visible (default)
|
||||||
|
browseable = yes
|
||||||
|
# restrict rights for new files/directories ("mask")
|
||||||
|
create mask = 0664
|
||||||
|
directory mask = 0775
|
||||||
|
# user and group membership (only effective with "unix extensions = no")
|
||||||
|
# No matter with which data a user logs on to the server,
|
||||||
|
# the data will be stored locally with these file affiliations.
|
||||||
|
force user = otto
|
||||||
|
force group = users
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Example 3**
|
||||||
|
|
||||||
|
Example of a share whose values are copied from share example2, overwriting all other data from the following options. In principle, no one is allowed to write except for the user paul and the members of the group example:
|
||||||
|
|
||||||
|
```
|
||||||
|
[example3]
|
||||||
|
# The settings of this share will be copied
|
||||||
|
copy = example2
|
||||||
|
path = /path/to/data3
|
||||||
|
# No write permissions for all (default)
|
||||||
|
writeable = no
|
||||||
|
# users, groups that are allowed to write anyway
|
||||||
|
write list = paul,@example
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
More about "Access controls for share definitions" can be found in the documentation [German Translation of Samba3 Files](https://sourceforge.net/projects/gertranssmb3.berlios/files/).
|
||||||
|
|
||||||
|
## Network Recycle Bin
|
||||||
|
|
||||||
|
> Simply moving files to the recycle bin of the respective desktop is not possible via Samba. However, the network recycle bin included in Samba (from version 3) can provide a remedy. If this is set up, then when files or folders are deleted, they are not immediately deleted permanently, but moved to a (possibly hidden) folder, from which they can then be permanently deleted in a second operation. This little-known option requires additional storage space on the server, but increases data security not inconsiderably.
|
||||||
|
|
||||||
|
The network recycle bin can be set up either in the [global] section generally for all shares, or for each share individually. To do this, simply add the line
|
||||||
|
|
||||||
|
```
|
||||||
|
vfs object = recycle
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
line. Further options allow you to specify the path to the recycle bin folder and its properties: enlarge
|
||||||
|
|
||||||
|
```
|
||||||
|
# A recycle bin is created:
|
||||||
|
vfs object = recycle
|
||||||
|
# The path to the recycle bin relative to the share (".recyclebin" is default).
|
||||||
|
recycle:repository = .recyclebin
|
||||||
|
# The recycle bin will keep path information.
|
||||||
|
recycle:keeptree = Yes
|
||||||
|
# When moving, the timestamp is adjusted.
|
||||||
|
recycle:touch = Yes
|
||||||
|
# Files with the same name are not overwritten.
|
||||||
|
recycle:versions = Yes
|
||||||
|
# No limitation of the file size.
|
||||||
|
recycle:maxsize = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The .recyclebin folder or the recycle bin folder specified by recycle:repository is then automatically created during the first delete operation. For more details, see here [samba.org](https://www.samba.org/samba/docs/current/man-html/vfs_recycle.8.html).
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
|
||||||
|
- [reddit.com](https://www.reddit.com/r/Proxmox/comments/mco03f/smb_cifs_share_provided_by_proxmox/)
|
||||||
|
- [wiki.ubuntuusers.de](https://wiki.ubuntuusers.de/Samba_Server/smb.conf/)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
# Samba cheat sheet (DE)
|
||||||
|
|
||||||
|
### Install dependencies for samba:
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt install samba
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Config samba server
|
||||||
|
|
||||||
|
> Bearbeiten Sie `/etc/samba/smb.conf`. Hier gibt es eine Menge von Optionen. Hier ist eine grundlegende Freigabekonfiguration. Fügen Sie diese am Ende der Datei ein.
|
||||||
|
|
||||||
|
```
|
||||||
|
[myshare]
|
||||||
|
comment = This is my share
|
||||||
|
path = /path/to/share/directory
|
||||||
|
browseable = yes
|
||||||
|
read only = no
|
||||||
|
guest ok = no
|
||||||
|
writable = yes
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Restart samba service
|
||||||
|
|
||||||
|
```
|
||||||
|
systemctl restart smbd
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
> Um eine Verbindung zu Ihrer Freigabe herzustellen, sofern Sie nicht nur einen Gastzugang verwenden, müssen Sie Samba-Benutzerkonten einrichten
|
||||||
|
|
||||||
|
```
|
||||||
|
smbpasswd -a {username [root, user]}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Heimatverzeichnisse
|
||||||
|
|
||||||
|
> Sind auf dem Server im Systemordner /home/ Heimatverzeichnisse für die einzelnen Benutzer eingerichtet, so können alle diese durch einen einzigen Eintrag in der Sektion [homes] freigegeben werden. Die dafür nötigen Einstellungen sind schon vorbereitet. Um diese kollektive Freigabe aller Heimatverzeichnisse zu aktivieren, muss man nur alle Semikolons ";" vor den Einträgen entfernen.
|
||||||
|
|
||||||
|
```
|
||||||
|
[homes]
|
||||||
|
comment = Home Directories
|
||||||
|
browseable = no
|
||||||
|
valid users = %S
|
||||||
|
writeable = yes
|
||||||
|
create mode = 0600
|
||||||
|
directory mode = 0700
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
> Die Heimverzeichnisse werden unter dem Namen des jeweiligen Benutzers freigegeben, aber wegen browseable = no nicht im Netzwerk angezeigt. Wegen valid users = %S hat nur der Benutzer mit dem passenden Namen Zugriff; andere Benutzer können die Freigabe weder sehen, noch lesen, noch schreiben. Wegen create mode = 0600 und directory mode = 0700 hat bei neu angelegten Dateien und Ordnern auch auf dem Server selbst nur der betreffende Benutzer Zugriffsrechte.
|
||||||
|
>
|
||||||
|
> Die Sektion [homes] stellt vor allem für Systeme mit vielen Benutzern gegenüber einzelnen Freigaben eine erhebliche Vereinfachung dar.
|
||||||
|
|
||||||
|
## Einzelne Freigaben
|
||||||
|
|
||||||
|
Anschließend werden die einzelnen Freigaben eingetragen. Eine Freigabe setzt sich aus dem Freigabenamen in eckigen Klammern - also [Beispielfreigabe] - und den danach folgenden Optionen zusammen. Die graphischen Oberflächen zu Samba tragen hier ebenfalls die Freigaben ein.
|
||||||
|
|
||||||
|
### Hinweis:
|
||||||
|
|
||||||
|
> Oft wird vergessen, dass die Zugriffsrechte in der Freigabe und im lokalen Dateisystem stimmen müssen. Erlaubt man z.B. den Zugriff von Gästen auf ein Verzeichnis, so muss der Benutzer nobody bzw. die Gruppe nogroup auch die entsprechenden lokalen Lese-/Schreibrechte in dem Verzeichnis haben.
|
||||||
|
|
||||||
|
### **Beispiel 1**
|
||||||
|
|
||||||
|
Beispiel für eine Freigabe, auf die nur angemeldete Benutzer zugreifen dürfen, wobei diese nur lesen aber nicht schreiben können. Die mit (Default) gekennzeichneten Einträge entsprechen den Standard-Einstellungen. Sie dienen nur zur Erläuterung und dürfen auch weggelassen werden:
|
||||||
|
|
||||||
|
```
|
||||||
|
[beispiel1]
|
||||||
|
# Pfad zu Verzeichnis
|
||||||
|
path = /pfad/zu/daten1
|
||||||
|
# Kommentar zur Freigabe
|
||||||
|
comment = Testfreigabe 1
|
||||||
|
# Freigabe ist aktiv (Default)
|
||||||
|
available = yes
|
||||||
|
# Freigabe ist direkt sichtbar (Default)
|
||||||
|
browseable = yes
|
||||||
|
# Gäste dürfen nicht auf die Freigabe zugreifen (Default)
|
||||||
|
guest ok = no
|
||||||
|
# Angemeldete Benutzer dürfen lesen aber nicht schreiben (Default).
|
||||||
|
writeable = no
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Beispiel 2**
|
||||||
|
|
||||||
|
Beispiel für eine Freigabe, auf die jeder - auch Gäste - sowohl lesend als auch schreibend zugreifen können. Des Weiteren wird auf die Daten lokal mit den Benutzerrechten otto und den Gruppenrechten users zugegriffen:
|
||||||
|
|
||||||
|
```
|
||||||
|
[beispiel2]
|
||||||
|
# Pfad zu Verzeichnis
|
||||||
|
path = /pfad/zu/daten2
|
||||||
|
# Auch Gäste dürfen auf die Freigabe zugreifen.
|
||||||
|
guest ok = yes
|
||||||
|
# Angemeldete Benutzer dürfen auch schreiben.
|
||||||
|
writeable = yes
|
||||||
|
# Freigabe ist direkt sichtbar (Default)
|
||||||
|
browseable = yes
|
||||||
|
# Rechte bei neuen Dateien/Verzeichnissen beschränken ("maskieren")
|
||||||
|
create mask = 0664
|
||||||
|
directory mask = 0775
|
||||||
|
# Benutzer und Gruppenzugehörigkeit (nur wirksam bei "unix extensions = no")
|
||||||
|
# Egal mit welchen Daten sich ein Benutzer am Server anmeldet,
|
||||||
|
# die Daten werden lokal mit diesen Dateizugehörigkeiten abgelegt.
|
||||||
|
force user = otto
|
||||||
|
force group = users
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### **Beispiel 3**
|
||||||
|
|
||||||
|
Beispiel für eine Freigabe, deren Werte von der Freigabe beispiel2 kopiert werden, wobei alle weiteren Angaben von den folgenden Optionen überschrieben werden. Prinzipiell darf niemand schreiben, bis auf den Benutzer paul und die Mitglieder der Gruppe beispiel:
|
||||||
|
|
||||||
|
```
|
||||||
|
[beispiel3]
|
||||||
|
# Die Einstellungen dieser Freigabe werden übernommen
|
||||||
|
copy = beispiel2
|
||||||
|
path = /pfad/zu/daten3
|
||||||
|
# Keine Schreibrechte für alle (Default)
|
||||||
|
writeable = no
|
||||||
|
# Benutzer, Gruppen die trotzdem schreiben dürfen
|
||||||
|
write list = paul,@beispiel
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Mehr zu dem Thema "Zugriffskontrollen für Freigabedefinitionen" findet sich in der Dokumentation [German Translation of Samba3 Files](https://sourceforge.net/projects/gertranssmb3.berlios/files/).
|
||||||
|
|
||||||
|
## Netzwerk-Papierkorb
|
||||||
|
|
||||||
|
> Das einfache Verschieben von Dateien in den Papierkorb des jeweiligen Desktop ist über Samba nicht möglich. Abhilfe kann jedoch der in Samba (ab Version 3) enthaltene Netzwerk-Papierkorb schaffen. Ist dieser eingerichtet, so werden beim Löschen von Dateien oder Ordnern diese nicht gleich endgültig gelöscht, sondern in einen (ggf. versteckten) Ordner verschoben, aus dem sie dann in einem zweiten Arbeitsgang endgültig gelöscht werden können. Diese wenig bekannte Möglichkeit benötigt zwar zusätzlichen Speicherplatz auf dem Server, erhöht aber die Datensicherheit nicht unerheblich.
|
||||||
|
|
||||||
|
Der Netzwerk-Papierkorb kann entweder im Abschnitt [global] generell für alle Freigaben, oder aber für jede Freigabe einzeln eingerichtet werden. Hierfür fügt man einfach die Zeile
|
||||||
|
|
||||||
|
```
|
||||||
|
vfs object = recycle
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
hinzu. Durch weitere Optionen kann man noch den Pfad zum Papierkorb-Ordner und dessen Eigenschaften festlegen: vergrößern
|
||||||
|
|
||||||
|
```
|
||||||
|
# Ein Papierkorb wird eingerichtet:
|
||||||
|
vfs object = recycle
|
||||||
|
# Der Pfad zum Papierkorb relativ zur Freigabe (".recyclebin" ist Default).
|
||||||
|
recycle:repository = .recyclebin
|
||||||
|
# Im Papierkorb bleiben Pfad-Angaben erhalten.
|
||||||
|
recycle:keeptree = Yes
|
||||||
|
# Beim Verschieben wird der Zeitstempel angepasst.
|
||||||
|
recycle:touch = Yes
|
||||||
|
# Gleichnamige Dateien werden nicht überschrieben.
|
||||||
|
recycle:versions = Yes
|
||||||
|
# Keine Begrenzung der Dateigröße.
|
||||||
|
recycle:maxsize = 0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Der Ordner .recyclebin bzw. der mittels recycle:repository festgelegte Papierkorb-Ordner wird dann beim ersten Löschvorgang automatisch angelegt. Weitere Einzelheiten siehe hier [samba.org](https://www.samba.org/samba/docs/current/man-html/vfs_recycle.8.html).
|
||||||
|
|
||||||
|
## Quellen
|
||||||
|
|
||||||
|
- [reddit.com](https://www.reddit.com/r/Proxmox/comments/mco03f/smb_cifs_share_provided_by_proxmox/)
|
||||||
|
- [wiki.ubuntuusers.de](https://wiki.ubuntuusers.de/Samba_Server/smb.conf/)
|
223
Filesystems/Zfs.md
Normal file
223
Filesystems/Zfs.md
Normal file
|
@ -0,0 +1,223 @@
|
||||||
|
# ZFS cheat sheet (EN)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## **Check the health of the pool's**
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool status
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
DiskID's can be retrieved with ls -l /dev/disk/by-id/ or ls -l /dev/disk/by-path/ alternativ you can use sdb and sdc
|
||||||
|
|
||||||
|
# Create Pool
|
||||||
|
|
||||||
|
### mirror pool
|
||||||
|
|
||||||
|
(similar to raid-1, ≥ 2 disks, 1:1 redundancy)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank mirror scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### raidz1 pool
|
||||||
|
|
||||||
|
(similar to raid-5, ≥ 3 disks, 1 disk redundancy)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank raidz scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### raidz2 pool
|
||||||
|
|
||||||
|
(similar to raid-6, ≥ 4 disks, 2 disks redundancy)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank raidz2 scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480 scsi-35000cca266ccbdb4
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### stripe pool
|
||||||
|
|
||||||
|
(similar to raid-0, no redundancy)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### single disk stripe pool
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank scsi-35000cca26c108480
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### 5 mirror
|
||||||
|
|
||||||
|
(like raid-10, 1:1 redundancy)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank mirror scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c\
|
||||||
|
mirror scsi-35000cca26c108480 scsi-35000cca266ccbdb4\
|
||||||
|
mirror scsi-35000cca266c75c74 scsi-35000cca26c0e84dc\
|
||||||
|
mirror scsi-35000cca266cda748 scsi-35000cca266cd14b4\
|
||||||
|
mirror scsi-35000cca266cb8ae4 scsi-35000cca266cbad80
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2 raidz
|
||||||
|
|
||||||
|
(like raid-50, 2 disks redundancy in total)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool create tank raidz scsi-35000cca2735cbc38 scsi-35000cca266cc4b3c scsi-35000cca26c108480 scsi-35000cca266ccbdb4 scsi-35000cca266c75c74\
|
||||||
|
raidz scsi-35000cca26c0e84dc scsi-35000cca266cda748 scsi-35000cca266cd14b4 scsi-35000cca266cb8ae4 scsi-35000cca266cbad80
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### ZFS can make use of fast SSD as second level cache (L2ARC) after RAM (ARC)
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool add tank cache nvme-MT001600KWHAC_S3M0NA0K700264
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# Mount
|
||||||
|
|
||||||
|
## mount a full pool
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir -p /data
|
||||||
|
zfs create -o mountpoint=/data tank/data
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## mount only a ZVOL of a Pool
|
||||||
|
|
||||||
|
```
|
||||||
|
zfs create -s -V 4GB tank/vol
|
||||||
|
mkfs.ext4 /dev/zvol/tank/vol
|
||||||
|
mount /dev/zvol/tank/vol /mnt
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## destroy previously created file systems and ZVOL
|
||||||
|
|
||||||
|
```
|
||||||
|
# ZFS will handle mounts that are managed by it
|
||||||
|
zfs destroy tank/data
|
||||||
|
# Need to umount first, because this mount is user managed
|
||||||
|
umount /dev/zvol/tank/vol
|
||||||
|
zfs destroy tank/vol
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
# Replace
|
||||||
|
|
||||||
|
You can replace a device in a storage pool by using the `zpool replace` command.
|
||||||
|
|
||||||
|
If you are physically replacing a device with another device in the same location in a redundant pool, then you might only need to identify the replaced device. ZFS recognizes that the device is a different disk in the same location on some hardware. For example, to replace a failed disk (c1t1d0) by removing the disk and replacing it in the same location, use the following syntax:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank c1t1d0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are replacing a device in a storage pool with a disk in a different physical location, you will need to specify both devices. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank c1t1d0 c1t2d0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are replacing a disk in the ZFS root pool, see How to Replace a Disk in the ZFS Root Pool.
|
||||||
|
|
||||||
|
The following are the basic steps for replacing a disk:
|
||||||
|
|
||||||
|
Offline the disk, if necessary, with the `zpool offline` command.
|
||||||
|
|
||||||
|
Remove the disk to be replaced.
|
||||||
|
|
||||||
|
Insert the replacement disk.
|
||||||
|
|
||||||
|
Run the `zpool replace` command. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank c1t1d0
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- Bring the disk online with the `zpool online` command.
|
||||||
|
|
||||||
|
# CIFS shares
|
||||||
|
|
||||||
|
CIFS is a dialect of Server Message Block (SMB) Protocol and could be used on Windows, VMS, several versions of Unix, and other operating systems. To share a dataset through CIFS, samba package needs to be installed:
|
||||||
|
|
||||||
|
```
|
||||||
|
apt install samba
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Because Microsoft Windows is not case sensitive, it is recommended to set casesensitivity=mixed to the dataset to be shared, and this property can only be set on creation time:
|
||||||
|
|
||||||
|
```
|
||||||
|
zfs create -o casesensitivity=mixed -o xattr=sa -o dnodesize=auto tank/data
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Configure a very simiple CIFS share (read/write to 192.168.0.0/24, read only to 10.0.0.0/8):
|
||||||
|
|
||||||
|
```
|
||||||
|
zfs set mountpoint=/data tank/data
|
||||||
|
zfs set sharesmb=on tank/data
|
||||||
|
zfs share tank/data
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Verify the share is exported successfuly:
|
||||||
|
|
||||||
|
```
|
||||||
|
smbclient -U guest -N -L localhost
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Stop the CIFS share:
|
||||||
|
|
||||||
|
```
|
||||||
|
zfs unshare tank/data
|
||||||
|
# If you want to disable the share forever, do the following
|
||||||
|
zfs sharesmb=off tank/data
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Replacing Devices in a Storage Pool If you are physically replacing a device with another device in the same location in a redundant pool, then you might only need to identify the replaced device. ZFS recognizes that the device is a different disk in the same location on some hardware. For example, to replace a failed disk (c1t1d0 or sdb) by removing the disk and replacing it in the same location, use the following syntax:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank {c1t1d0 or sdb/sdc}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are replacing a device in a storage pool with a disk in a different physical location, you will need to specify both devices. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank {c1t1d0 or sdb/sdc} {c1t2d0 or sdd/sde}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
If you are replacing a disk in the ZFS root pool, see How to Replace a Disk in the ZFS Root Pool.
|
||||||
|
|
||||||
|
The following are the basic steps for replacing a disk: Offline the disk, if necessary, with the zpool offline command. Remove the disk to be replaced. Insert the replacement disk. Run the zpool replace command. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
zpool replace tank {c1t1d0 or sdb/sdc}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quelle
|
||||||
|
|
||||||
|
- https://wiki.debian.org/ZFS#Creating_the_Pool
|
||||||
|
- https://docs.oracle.com/cd/E19253-01/819-5461/gazgd/index.html
|
Loading…
Add table
Add a link
Reference in a new issue