|
|
|
Im Gegensatz zu DOS/Windows kann ein Befehl länger als eine Kommandozeile sein.
Auch bietet Linux die Möglichkeit, Befehle zu verschachteln.
Dieses geschieht mittels der Pipe: |
Nehmen wir an, wir wollen alle Dateien eines Verzeichnisses
anzuzeigen, die Anzahl überschreitet jedoch die Bildschirmzeilenanzahl.
Also koppeln wir den ls - Befehl (mit z.B. dem Parameter -l) mittels der Pipe mit dem more - Befehl:
ls -l /usr/src/linux/ | more insgesamt 4132 drwxr-xr-x 21 root root 4096 2003-10-18 07:13 arch -rw-r--r-- 1 root root 18691 2003-10-18 07:11 COPYING -rw-r--r-- 1 root root 81829 2003-10-18 07:11 CREDITS drwxr-xr-x 2 root root 4096 2003-10-18 06:22 crypto drwxr-xr-x 33 root root 4096 2003-10-18 07:13 Documentation drwxr-xr-x 40 root root 4096 2003-10-18 06:16 drivers drwxr-xr-x 49 root root 4096 2003-10-18 06:21 fs drwxr-xr-x 30 root root 4096 2003-11-08 18:52 include drwxr-xr-x 2 root root 100 2003-10-18 06:17 init drwxr-xr-x 2 root root 4096 2003-10-18 06:22 ipc drwxr-xr-x 3 root root 4096 2003-10-18 06:17 kernel drwxr-xr-x 4 root root 4096 2003-10-18 06:22 lib -rw-r--r-- 1 root root 47594 2003-10-18 07:11 MAINTAINERS -rw-r--r-- 1 root root 20156 2003-10-18 07:11 Makefile drwxr-xr-x 2 root root 4096 2003-10-18 06:18 mm drwxr-xr-x 29 root root 4096 2003-10-18 06:22 net -rw-r--r-- 1 root root 14287 2003-10-18 07:11 README -rw-r--r-- 1 root root 2818 2003-10-18 07:11 REPORTING-BUGS -rw-r--r-- 1 root root 9601 2003-10-18 07:11 Rules.make drwxr-xr-x 4 root root 4096 2003-10-18 06:17 scripts -rw-r--r-- 1 root root 584054 2003-10-18 06:22 System.map --Mehr--
|
Man kann natürlich auch die Bildschirmausgabe umleiten, um eine Datei zu erzeugen.
Hier gibt es 2 Zustände:
> erzeugt immer wieder eine neue Datei
ls -l /etc > /tmp/dir.txt |
erzeugt eine neue Datei mit dem Namen dir.txt im Verzeichnis /tmp, die als Inhalt die Auflistung vom Verzeichnis /etc enthält.
Jedesmal, wenn diese Konstellation eingegeben wird, wird eine neue dir.txt angelegt.
>> hängt die Ausgabe an eine bestehende Datei an (oder erzeugt eine neue, wenn noch nicht vorhanden)
ls -l /etc >> /tmp/dir.txt |
Dieser Befehl bewirkt das selbe wie oben (es wird der Inhalt des Verzeichnisses /etc in die Datei geschrieben), jedoch wird, wenn die Datei dir.txt noch nicht vorhanden ist, eine neue erzeugt; ansonst wird der Inhalt an die Datei dir.txt angehängt. |
|