<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zInformatik &#187; Bash</title>
	<atom:link href="http://zinformatik.de/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://zinformatik.de</link>
	<description>Computer, Informatik und Mikrocontroller Blog</description>
	<lastBuildDate>Sat, 22 Oct 2011 09:51:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Die Z-Shell (zsh) &#8211; Eine mächtige Alternative zur Bash</title>
		<link>http://zinformatik.de/tipps-tricks/interessante-programme/die-z-shell-zsh-eine-machtige-alternative-zur-bash/</link>
		<comments>http://zinformatik.de/tipps-tricks/interessante-programme/die-z-shell-zsh-eine-machtige-alternative-zur-bash/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:44:52 +0000</pubDate>
		<dc:creator>zimon</dc:creator>
				<category><![CDATA[Interessante Programme]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntuusers-Planet]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Konsole]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://zinformatik.de/?p=1668</guid>
		<description><![CDATA[Die Standardshell auf den meisten Linux-Systemen ist die Bash. Sie ist schon sehr mächtig und erlaubt es viele Aufgaben zu automatisieren. Dieser Artikel soll sich einer sehr interessanten weil noch mächtigeren Shell widmen, der Z-Shell kurz zsh.
]]></description>
			<content:encoded><![CDATA[<p>Die Standardshell auf den meisten Linux-Systemen ist die Bash. Sie ist schon sehr mächtig und erlaubt es viele Aufgaben zu automatisieren. Dieser Artikel soll sich einer sehr interessanten weil noch mächtigeren Shell widmen, der Z-Shell kurz zsh.</p>
<p>Die zsh lässt sich auf quasi allen Linuxsystemen über die Paketverwaltung installieren. Unter Ubuntu z.B. mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">zsh</span></pre></div></div>

<p>Danach kann man sie mit dem Aufruf von <code>zsh</code> ausführen. Um sie zur Standardshell zu machen genügt der Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chsh</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">zsh</span> username</pre></div></div>

<p>Wobei <code>username</code> durch den entsprechenden Usernamen ersetzt werden muss und der Pfad zu <code>zsh</code> stimmen muss. Auf manchen Systemen liegt <code>zsh</code> in <code>/bin</code>. Wo <code>zsh</code> liegt kann man mit dem folgenden Befehl heraus finden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">which</span> <span style="color: #c20cb9; font-weight: bold;">zsh</span></pre></div></div>

<p>Die zsh bedient sich Elementen der Bash, der Korn-Shell (ksh) und der TENEX-C-Shell (tcsh &#8211; eine erweiterte C-Shell). Sie ist sehr gut konfigurierbar und fast jedes Verhalten der Bash kann nachgeahmt werden so dass der Umstieg sehr leicht fällt. Bestehende Bash-Scripte können natürlich weiterhin genutzt werden, wenn der Shebang entsprechend gesetzt ist. Also in der ersten Zeile folgendes steht:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span></pre></div></div>

<p>Im Folgenden werde ich einige interessante Vorteile der zsh kurz beschreiben. Zu einzelnen Themen werde wahrscheinlich in anderen Artikel ausführlicher eingehen. Dies sollen also nur Beispiele sein, die die Mächtigkeit demonstrieren sollen. Da die zsh so viele Möglichkeiten bietet ist es nicht möglich hier alles im Detail zu erläutern. Optionen werden mit dem Befehl <code>setopt</code> gesetzt. Dies kann man auch so in die Konfigurationsdatei <code>~/.zshrc</code> schreiben.</p>
<p><strong>Autokorrektur</strong><br />
Die zsh beherrscht einen Mechanismus, der kleine Tippfehler automatisch korrigiert. Hat man in einem Ordner eine Datei <code>testfile.txt</code> und möchte diese kopieren nach <code>file2.txt</code>, so führt man in der Regel folgenden Befehl aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> testfile.txt file2.txt</pre></div></div>

<p>wie von der Bash gewohnt nutzt man dafür die Autovervollständigung mittels TAB. Bei einem Verschreiber wird dieser in der zsh automatisch korrigiert. Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> tsetf<span style="color: #000000; font-weight: bold;">&lt;</span>TAB<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>wird automatisch korrigiert und zu</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> testfile.txt</pre></div></div>

<p>vervollständigt.</p>
<p>Die Autokorrektur aktiviert man mit der Option <code>correct</code></p>
<p><strong>Globale Aliase</strong><br />
Neben den normalen Aliasen für Kommandos, wie man sie aus der Bash kennt, gibt es in der zsh noch globale Aliase, die überall im Befehl genutzt werden können, nicht nur am Anfang. Zwei Beispiele verdeutlichen dies:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #660033;">-g</span> <span style="color: #007800;">G</span>=<span style="color: #ff0000;">'| grep'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #660033;">-g</span> <span style="color: #007800;">L</span>=<span style="color: #ff0000;">'| less'</span></pre></div></div>

<p>erzeugt die globalen Aliase G und L die man hinter alle möglichen Befehle schreiben kann um die Ausgabe des entsprechenden Befehls in grep oder less zu pipen. Z.B.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> G txt</pre></div></div>

<p>entspricht dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> txt</pre></div></div>

<p>oder</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-e</span> L</pre></div></div>

<p>entspricht</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ps</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">less</span></pre></div></div>

<p>Natürlich ist auch folgendes Möglich:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> G txt L</pre></div></div>

<p>was folgendem Befehl entspricht:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">less</span></pre></div></div>

<p><strong>Suffix Aliase</strong><br />
Mit Suffixaliasen kann man Programme festlegen, mit denen bestimmte Dateitypen (anhand ihrer Endung) geöffnet werden sollen. Man braucht dann nur noch den Namen der Datei eingeben und sie wird mit dem entsprechenden Programm geöffnet. Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">pdf</span>=evince</pre></div></div>

<p>legt einen Alias für pdf Dateien an. Sie sollen mit evince geöffnet werden. Danach reicht die Eingabe von</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dokument.pdf</pre></div></div>

<p>und die Datei <code>dokument.pdf</code> wird mit evince geöffnet.</p>
<p><strong>Aliase für Verzeichnisse: Hashes</strong><br />
Mit sogenannten Hashes lassen sich Aliase für beliebige Verzeichnisse anlegen. Auf diese kann dann sehr einfach zugegriffen werden. Mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">hash</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">perl</span>=~<span style="color: #000000; font-weight: bold;">/</span>developement<span style="color: #000000; font-weight: bold;">/</span>scripting<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">perl</span></pre></div></div>

<p>legt man einen Hash namens <code>perl</code> für das Verzeichnis <code>~/developement/scripting/perl</code> an. Auf dieses Verzeichnis kann man jetzt mit <code>~perl</code> zugreifen. Auch innerhalb eines Befehls wie folgendes Beispiel zeigt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> testscript.pl ~<span style="color: #c20cb9; font-weight: bold;">perl</span></pre></div></div>

<p>Dieser Befehl kopiert die Datei <code>testscript.pl</code> in das Verzeichnis <code>~/developement/scripting/perl</code>.</p>
<p><strong>Auto-CD</strong><br />
Mit der Option <code>autocd</code> kann man zum Wechseln in ein Verzeichnis einfach den Namen eines Verzeichnisses eingeben und das Kommando <code>cd</code> davor einfach weglassen. Wenn es keinen Befehl gibt, der so heißt wie das Verzeichnis, so wird in das Verzeichnis gewechselt.</p>
<p><strong>Kurze for-Schleifen</strong><br />
Statt einem</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.eps; <span style="color: #000000; font-weight: bold;">do</span> epstopdf <span style="color: #007800;">$i</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>um alle eps-Dateien in einem Verzeichnis in pdf-Dateien umzuwandeln genügt unter zsh die kürzere Form</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">*</span>.eps<span style="color: #7a0874; font-weight: bold;">&#41;</span> epstopdf <span style="color: #007800;">$i</span></pre></div></div>

<p><strong>Globale History</strong><br />
Die History, die man mit der Pfeil-auf Taste durchgehen kann, kann man in der zsh so einstellen, dass sie in jeder zsh-Instanz gleich ist. Das heißt man hat nicht mehr für jedes Fenster seine eigene History sondern kann mit der Pfeil-auf Taste auch Befehle raussuchen, die in anderen Fenstern eingegeben wurden. Die History wird jedoch nur nach jedem Befehl geupdated, das heißt man muss ggf. einmal Return drücken, damit die Befehle aus einem anderen Fenster verfügbar sind.</p>
<p>Dieses Verhalten kann mit der Option <code>share_history</code> aktiviert werden.</p>
<p><strong>Directory Stack</strong><br />
Wie Bash, hat die zsh auch einen Directory stack. Mit dem Befehl <code>pushd</code> kann man das aktuelle Verzeichnis auf den Stack legen und mit <code>popd</code> das jeweils letzte Verzeichnis vom Stack nehmen und dorthin springen. Mit der Option <code>auto_pushd</code> legt die zsh automatisch jedes Verzeichnis auf den Directorystack, aus welchem man in ein anderes Verzeichnis wechselt. So hat man immer eine History der Verzeichnisse in denen man war und kann mit <code>popd</code> sehr einfach wieder in Verzeichnisse welchseln, die man vorher besucht hatte.</p>
<p><strong>Globbing</strong><br />
Die Nutzung von Wildcards &#8211; unter zsh globbing genannt &#8211; ist bei der Z-Shell wesentlich mächtiger als in der Bash. Zunächst gibt es rekursives Globbing (gibts in der Bash in neueren Versionen wohl auch). So kann man mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">**/*</span>.html</pre></div></div>

<p>alle HTML-Dateien im aktuellen Verzeichnis und allen Unterverzeichnissen auflisten lassen.</p>
<p>Es gibt jedoch auch noch Qualifier um Dateien mit bestimmten Eigenschaften auszuwählen. Diese schreibt man in runde Klammern. So kann man mit <code>.</code> normale Dateien, mit <code>/</code> Verzeichnisse und mit <code>@</code> Symbolische Links matchen. Praktisch ist das z.B. wenn man allen Verzeichnissen ab einem bestimmten Verzeichnis die Rechte 755 und allen Dateien 644 vergeben möchte. Dies kann man mit den folgenden zwei Befehlen bewerkstelligen statt mit <code>find</code> und <code>exec</code> zu arbeiten.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">**/*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> <span style="color: #000000; font-weight: bold;">**/*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Zusätzlich gibt es auch Qualifier für verschiedenste Dateirechte. Folgender Befehl listet alle Dateien auf, die von allen beschrieben werden können:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">**/*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.W<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Auch nach der Dateigröße lässt sich suchen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">print <span style="color: #000000; font-weight: bold;">**/*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>L0<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>listet alle leeren Dateien auf.</p>
<p>Auch die Sortierung lässt sich beliebig anpassen. Mit dem Befehl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">print <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>oL<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Listet alle Dateien der Größe nach von klein nach groß auf. Mit großem O wird die Sortierung umgekehrt.</p>
<p>Somit lässt sich mittels globbing in der zsh das Kommando <code>find</code> quasi komplett ersetzen. Die hier gezeigten Beispiele sehen auf den ersten Blick recht kompliziert und kryptisch aus. Wenn man das Prinzip aber einmal verstanden hat und die wichtigsten Qualifier kennt ist es aber ganz einfach und sehr praktisch.</p>
<p>Es gibt noch jede Menge weiterer Qualifier und Möglichkeiten für das Globbing (z.B. nur das erste oder eine bestimmte Anzahl von Elementen auszuwählen), die ich hier gar nicht alle erwähnen kann. Im zsh-Manual gibt es jedoch eine Liste der <a href="http://zsh.sourceforge.net/Doc/Release/Expansion.html#SEC87" title="zsh-Manual - Glob-Qualifier" target="_blank" class="liexternal">Glob-Qualifier</a>.</p>
<p>Um alle Möglichkeiten nutzen zu können sollte die Option <code>extended_glob</code> gesetzt werden.</p>
<p><strong>Vervollständigung</strong><br />
Die zsh hat wie die Bash einen Vervollständigungsmechanismus, so dass man mit der TAB-Taste Kommandos, Dateinamen und vieles mehr vervollständigen kann. In der zsh ist dieser Mechanismus jedoch extrem gut konfigurierbar und programierbar. So kann man z.B. beim <code>scp</code> Befehl (der Dateien über ssh kopiert) die <a href="http://blog.pimpmyshell.de/2007/01/21/ssh-completion-mit-zsh/" title="ssh completion mit zsh" target="_blank" class="liexternal">Verzeichnisse auf dem entfernten Rechner vervollständigen</a> und genau definieren welche Programme mit welchen Dateitypen zusammen arbeiten können. Für sehr viele Programme ist dies schon vorgefertigt, so dass ein</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">latex doku<span style="color: #000000; font-weight: bold;">&lt;</span>TAB<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>automatisch zu</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> latex dokument.tex</pre></div></div>

<p>vervollständigt wird. Dies beherrscht die Bash zum Teil auch. Jedoch ist es in der zsh wesentlich besser konfigurierbar und anpassbar.</p>
<p>Sehr praktisch finde ich auch die Menüfunktion. So wird beim ersten Druck auf die TAB-Taste wie in der Bash soweit vervollständigt, bis nicht mehr entschieden werden kann welche Datei (bzw. welcher Befehl) gemeint ist. Ein weiterer Druck auf die TAB-Taste listet alle weiteren Möglichkeiten auf und jeder weitere Druck geht diese Möglichkeiten durch. Wenn ich also drei Dateien habe: <code>test.txt</code>, <code>testfile1.txt</code> und <code>testfile2.txt</code> und gebe folgendes ein:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> te<span style="color: #000000; font-weight: bold;">&lt;</span>TAB<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>so wird zuerst auf <code>test</code> vervollständigt. Ein weiterer Druck gibt mir alle Möglichkeiten aus:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">testfile1.txt  testfile2.txt  test.txt</pre></div></div>

<p>und ein dritter Druck auf die Tab-Taste vervollständigt den Befehl zu</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> testfile1.txt</pre></div></div>

<p>Das ist viel schneller als erst ein <code>f</code> einzugeben um erneut TAB zu drücken und dann die <code>1</code> einzugeben um wiederum TAB zu drücken bis der Dateiname endgültig vervollständigt wird.</p>
<p>Ein weiterer Druck auf TAB nimmt dann die nächste Möglichkeit. In diesem Beispiel also</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> testfile2.txt</pre></div></div>

<p>und so weiter.</p>
<p><strong>Expansion</strong><br />
Mit der TAB-Taste kann man in der zsh nicht nur Kommandos, Dateinamen, &#8230; vervollständigen, sondern auch Variablen expandieren. Viele kennen ja die spezielle Variable <code>!!</code>, die den zuletzt ausgeführten Befehl enthält. In der zsh kann man nun folgendes eingeben:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!!&lt;</span>TAB<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>und die Variable <code>!!</code> wird automatisch zum zuletzt ausgeführten Befehl expandiert. Genauso kann man auch jede andere Variable expandieren:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">&lt;</span>TAB<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>wird zu <code>/home/zimon/developement</code> (vorrausgesetzt ich befinde mich zum Zeitpunkt der expansion in diesem Verzeichnis).</p>
<p><strong>History Kontrolle</strong><br />
Wie bei der Bash auch, kann man in der zsh die History durchsuchen. Die zsh geht jedoch so weit, dass man auch nach bestimmten Parametern suchen kann. Ein Beispiel:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> ..<span style="color: #000000; font-weight: bold;">/</span>perl<span style="color: #000000; font-weight: bold;">/</span>foo.pl ~<span style="color: #000000; font-weight: bold;">/</span>developement<span style="color: #000000; font-weight: bold;">/</span>projektordner</pre></div></div>

<p>Danach kommen ein paar andere Kommandos. Möchte nun eine andere Datei in den gleichen Projektordner kopieren reicht folgende Eingabe:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> ..<span style="color: #000000; font-weight: bold;">/</span>perl<span style="color: #000000; font-weight: bold;">/</span>bar.pl <span style="color: #000000; font-weight: bold;">!</span>?proj?:<span style="color: #000000;">3</span></pre></div></div>

<p>Mit !? wird nach einem vorherigen Befehl gesucht. Das <code>proj</code> ist ein String der in diesem Befehl vorkam. Mit dem <code>?:3</code> wird das dritte Argument genutzt. Durch die Expansion kann manmit durch einen Druck auf TAB diesen Ausdruck auch noch expandieren um sicher zu gehen, dass das richtige Argument ausgewählt wurde. Man kann zwar mit Alt+. wie in der Bash die jeweils letzten Argumente durchgehen, auf diese Weise kann man aber auch das zweite von drei Argumenten suchen.</p>
<p>Es gibt noch wesentlich mehr Möglichkeiten die History zu durchsuchen und zu verwenden.</p>
<p><strong>Hochkonfigurierbarer Prompt</strong><br />
In der Z-Shell kann man nicht nur die linke Seite des Prompts sondern auch die rechte Seite konfigurieren. Als Beispiel hier mal mein aktueller Prompt:</p>
<div id="attachment_1679" class="wp-caption aligncenter" style="width: 643px"><a href="http://zinformatik.de/wp-content/uploads/2010/01/zsh_prompt.png" class="liimagelink"><img class="size-full wp-image-1679" title="zsh Prompt" src="http://zinformatik.de/wp-content/uploads/2010/01/zsh_prompt.png" alt="zsh Prompt" width="633" height="37" /></a><p class="wp-caption-text">Mein aktueller zsh-Prompt</p></div>
<p>Ich finde die Anzeige der Uhrzeit inklusive Sekunden recht praktisch, da man daran sieht wie lange ein Befehl gedauert hat oder wann man ihn ausgeführt hat. Es gibt jedoch auch die Möglichkeit automatisch die Ausgabe von <code>time</code> bei der Beendigung eines Befehls ausgeben zu lassen, der länger als eine vorher definierte Zeit benötigt hat.</p>
<p>Der Prompt ist eine abgeänderte Version von <a href="http://aperiodic.net/phil/prompt/" title="Phil!s ZSH Prompt" target="_blank" class="liexternal">Phil!s ZSH Prompt</a>.</p>
<p><strong>[UPDATE]</strong> Auf Anfrage hin ist hier noch der Code für die von mir abgeänderte Version des Prompts:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">setprompt <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># Need this so the prompt will work.</span>
&nbsp;
    setopt prompt_subst
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># See if we can use colors.</span>
&nbsp;
    autoload colors zsh<span style="color: #000000; font-weight: bold;">/</span>terminfo
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$terminfo</span>[colors]&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #000000;">8</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	colors
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">for</span> color <span style="color: #000000; font-weight: bold;">in</span> RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">eval</span> PR_<span style="color: #007800;">$color</span>=<span style="color: #ff0000;">'%{$terminfo[bold]$fg[${(L)color}]%}'</span>
	<span style="color: #7a0874; font-weight: bold;">eval</span> PR_LIGHT_<span style="color: #007800;">$color</span>=<span style="color: #ff0000;">'%{$fg[${(L)color}]%}'</span>
	<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> count = <span style="color: #007800;">$count</span> + <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">done</span>
    <span style="color: #007800;">PR_NO_COLOUR</span>=<span style="color: #ff0000;">&quot;%{<span style="color: #007800;">$terminfo</span>[sgr0]%}&quot;</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># See if we can use extended characters to look nicer.</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">typeset</span> <span style="color: #660033;">-A</span> altchar
    <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-A</span> altchar <span style="color: #800000;">${(s..)terminfo[acsc]}</span>
    <span style="color: #007800;">PR_SET_CHARSET</span>=<span style="color: #ff0000;">&quot;%{<span style="color: #007800;">$terminfo</span>[enacs]%}&quot;</span>
    <span style="color: #007800;">PR_SHIFT_IN</span>=<span style="color: #ff0000;">&quot;%{<span style="color: #007800;">$terminfo</span>[smacs]%}&quot;</span>
    <span style="color: #007800;">PR_SHIFT_OUT</span>=<span style="color: #ff0000;">&quot;%{<span style="color: #007800;">$terminfo</span>[rmacs]%}&quot;</span>
    <span style="color: #007800;">PR_HBAR</span>=<span style="color: #800000;">${altchar[q]:--}</span>
    <span style="color: #007800;">PR_ULCORNER</span>=<span style="color: #800000;">${altchar[l]:--}</span>
    <span style="color: #007800;">PR_LLCORNER</span>=<span style="color: #800000;">${altchar[m]:--}</span>
    <span style="color: #007800;">PR_LRCORNER</span>=<span style="color: #800000;">${altchar[j]:--}</span>
    <span style="color: #007800;">PR_URCORNER</span>=<span style="color: #800000;">${altchar[k]:--}</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> == <span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #007800;">PR_HBAR</span>=-
     	<span style="color: #007800;">PR_ULCORNER</span>=--
    	<span style="color: #007800;">PR_LLCORNER</span>=--
    	<span style="color: #007800;">PR_LRCORNER</span>=--
    	<span style="color: #007800;">PR_URCORNER</span>=-
   <span style="color: #000000; font-weight: bold;">fi</span> 
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># Decide if we need to set titlebar text.</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$TERM</span> <span style="color: #000000; font-weight: bold;">in</span>
	xterm<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	    <span style="color: #007800;">PR_TITLEBAR</span>=$<span style="color: #ff0000;">'%{\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\a%}'</span>
	    <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #c20cb9; font-weight: bold;">screen</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	    <span style="color: #007800;">PR_TITLEBAR</span>=$<span style="color: #ff0000;">'%{\e_screen \005 (\005t) | %(!.-=[ROOT]=- | .)%n@%m:%~ | ${COLUMNS}x${LINES} | %y\e\\%}'</span>
	    <span style="color: #000000; font-weight: bold;">;;</span>
	<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
	    <span style="color: #007800;">PR_TITLEBAR</span>=<span style="color: #ff0000;">''</span>
	    <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># Decide whether to set a screen title</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> == <span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">PR_STITLE</span>=$<span style="color: #ff0000;">'%{\ekzsh\e\\%}'</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">PR_STITLE</span>=<span style="color: #ff0000;">''</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
    <span style="color: #666666; font-style: italic;">###</span>
    <span style="color: #666666; font-style: italic;"># Finally, the prompt.</span>
&nbsp;
    <span style="color: #007800;">PROMPT</span>=<span style="color: #ff0000;">'$PR_SET_CHARSET$PR_STITLE${(e)PR_TITLEBAR}\
$PR_RED$PR_SHIFT_IN$PR_ULCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_GREEN%(!.%SROOT%s.%n)$PR_GREEN@%m:%l\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_RED$PR_HBAR${(e)PR_FILLBAR}$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
$PR_MAGENTA%$PR_PWDLEN&lt;...&lt;%~%&lt;&lt;\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_RED$PR_URCORNER$PR_SHIFT_OUT\
&nbsp;
$PR_RED$PR_SHIFT_IN$PR_LLCORNER$PR_BLUE$PR_HBAR$PR_SHIFT_OUT(\
%(?..$PR_LIGHT_RED%?$PR_BLUE:)\
${(e)PR_APM}$PR_YELLOW%D{%H:%M:%S}\
$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_RED$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_NO_COLOUR '</span>
&nbsp;
    <span style="color: #007800;">RPROMPT</span>=<span style="color: #ff0000;">' $PR_RED$PR_SHIFT_IN$PR_HBAR$PR_BLUE$PR_HBAR$PR_SHIFT_OUT\
($PR_YELLOW%D{%a,%b%d}$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_RED$PR_LRCORNER$PR_SHIFT_OUT$PR_NO_COLOUR'</span>
&nbsp;
    <span style="color: #007800;">PS2</span>=<span style="color: #ff0000;">'$PR_RED$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_BLUE$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT(\
$PR_LIGHT_GREEN%_$PR_BLUE)$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT\
$PR_RED$PR_SHIFT_IN$PR_HBAR$PR_SHIFT_OUT$PR_NO_COLOUR '</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
setprompt</pre></div></div>

<p><strong>[/UPDATE]</strong></p>
<p><strong>ZLE-Widgets</strong><br />
Der Z-Line-Editor (ZLE) ist quasi die Eingabezeile in der zsh. Dafür kann man sich kleine Programme schreiben, die einem das Leben vereinfachen. Ein Beispiel wäre ein Programm, dass bei der Eingabe von <code>...</code> diese zu <code>../..</code> umwandelt. Jeder weitere Punkt wird wieder umgewandelt. So kann man recht einfach folgendes eingeben:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ....<span style="color: #000000; font-weight: bold;">/</span>directory</pre></div></div>

<p>Auf dem Bildschirm erscheint jedoch folgendes:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>directory</pre></div></div>

<p>Dieses Widget ist kein Standard bei der Z-Shell. Man kann es aber durch folgenden Code in der Konfigurationsdatei <code>~/.zshrc</code> erzeugen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rationalise-dot<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$LBUFFER</span> = <span style="color: #000000; font-weight: bold;">*</span>.. <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        LBUFFER+=<span style="color: #000000; font-weight: bold;">/</span>..
    <span style="color: #000000; font-weight: bold;">else</span>
        LBUFFER+=.
            <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
zle <span style="color: #660033;">-N</span> rationalise-dot
bindkey . rationalise-dot</pre></div></div>

<p><strong>Automatisches tee-ing</strong><br />
In der Z-Shell kann man die Ausgabe eines Kommandos recht einfach in mehrere verschiedene Dateien umleiten. Statt wie in der Bash</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> all <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> actual</pre></div></div>

<p>zu schreiben, kann man in der zsh einfach</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span>all <span style="color: #000000; font-weight: bold;">&gt;</span>actual</pre></div></div>

<p>eingeben. Beide Befehle führen ls aus und hängen die Ausgabe an die Datei <code>all</code> an und schreiben sie in die Datei <code>actual</code> wobei der inhalt jeweils überschrieben wird.<br />
Möchte man die Ausgabe wie beim original <code>tee</code> Befehl auch auf dem Bildschirm sehen, so leitet man sie auch noch auf STDOUT um:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span>all <span style="color: #000000; font-weight: bold;">&gt;</span>actual <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span></pre></div></div>

<p><strong>Verzeichnisse durch Ersetzung wechseln</strong><br />
Ein Beispiel sollte dies am besten Erklären. Man nehme an man hat zwei Verzeichnisse: <code>~/developement/scripting/perl/modules</code> und <code>~/developement/scripting/python/modules</code> und man befindet sich in <code>~/developement/scripting/perl/modules</code>, so kann man durch den Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #c20cb9; font-weight: bold;">perl</span> python</pre></div></div>

<p>in das Verzeichnis <code>~/developement/scripting/python/modules</code> wechseln. Bei einem <code>cd</code> Kommando mit zwei Parametern wird im aktuellen Verzeichnis-String das erste Wort durch das zweite ersetzt. Hier also <code>perl</code> durch <code>python</code>.</p>
<p><strong>Fazit</strong><br />
Ich bin jetzt nicht 100% sicher, dass alles hier beschriebene nicht auch in der Bash möglich ist. Es zeigt aber auf jeden Fall, dass die Z-Shell jede Menge interessante Möglichkeiten bietet und man viele Dinge einfacher und schneller erledigen kann als in der Bash. Die oben gezeigten Features sind meist nur angerissen und nur eine kleine Auswahl von dem was die Z-Shell bietet. Darüber hinaus besitzt die Z-Shell eine ganze Reihe Module z.B. für Matheoperationen oder einen eigenen FTP-Client, die man bei Bedarf laden kann.</p>
<p>Sehr schön ist auch die Möglichkeit den <a href="http://zinformatik.de/linux/titel-von-screen-fenstern-automatisch-von-vim-bash-und-zsh-setzen/" title="Titel von Screen Fenstern automatisch von vim, Bash und zsh setzen" target="_self" class="liinternal">Screen-Title von der zsh aus zu setzen</a>.</p>
<p>Es lohnt sich auf jeden Fall, diese Shell etwas genauer zu betrachten. Bei mir hat sie mittlerweile die Bash fast vollständig ersetzt (vorhandene Scripte habe ich nicht umgeschrieben).</p>
<p><strong>Links</strong></p>
<ul>
<li><a href="http://zsh.sourceforge.net/" title="Offizielle zsh Projektseite" target="_blank" class="liexternal">Offizielle zsh Projektseite</a> (englisch)</li>
<li><a href="http://zsh.sourceforge.net/Doc/Release/zsh_toc.html" title="zsh Manual" target="_blank" class="liexternal">zsh Manual</a> (englisch)</li>
<li><a href="http://zsh.sourceforge.net/Guide/zshguide.html" title="zsh Users Guide" target="_blank" class="liexternal">zsh User&#8217;s Guide</a> (englisch)</li>
<li><a href="http://michael-prokop.at/computer/tools_zsh.html" title="zsh generell" target="_blank" class="liexternal">Michael Prokops zsh Seite</a> &#8211; Seite mit Features und Beispielen wo zsh mit Bash verglichen wird</li>
<li><a href="http://michael-prokop.at/computer/tools_zsh_liebhaber.html" title="zsh liebhaber" target="_blank" class="liexternal">Michael Prokops zsh Liebhaberseite</a> &#8211; Viele gute Beispiele und zsh Tricks angelehnt an das zsh-lovers Projekt.</li>
<li><a href="http://zshwiki.org" title="zsh wiki" target="_blank" class="liexternal">zsh wiki</a> &#8211; Wiki über zsh (englisch)</li>
<li><a href="http://grml.org/zsh/zsh-lovers.html" title="zsh-lovers" target="_blank" class="liexternal">zsh-lovers</a> &#8211; Sammlung von Tipps, Tricks und Beispielen (englisch)</li>
<li><a href="http://grml.org/zsh/" target="_blank" class="liexternal">grml zsh Seite</a> &#8211; Seite mit sehr großer zsh-Konfigurationsdatei, Referenzkarte und anderen zsh Infos. Die grml-Linuxdistribution hat zsh als Standardshell. (englisch)</li>
<li><a href="http://www.strcat.de/zsh/" title="stcats zsh Page" target="_blank" class="liexternal">strcat.de/zsh/</a> &#8211; Seite mit Auflistung vieler Features und Tipps (englisch)</li>
<li><a href="http://rayninfo.co.uk/tips/zshtips.html" title="Best of zsh Tips" target="_blank" class="liexternal">Zzappers Best of ZSH Tips</a> &#8211; Viele zsh Tipps (englisch)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://zinformatik.de/tipps-tricks/interessante-programme/die-z-shell-zsh-eine-machtige-alternative-zur-bash/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Erinnerungen mit at und zenity</title>
		<link>http://zinformatik.de/linux/erinnerungen-mit-at-und-zenity/</link>
		<comments>http://zinformatik.de/linux/erinnerungen-mit-at-und-zenity/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 17:59:53 +0000</pubDate>
		<dc:creator>zimon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tipps und Tricks]]></category>
		<category><![CDATA[Ubuntuusers-Planet]]></category>
		<category><![CDATA[at]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Erinnerung]]></category>
		<category><![CDATA[Konsole]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[zenity]]></category>

		<guid isPermaLink="false">http://zinformatik.de/?p=1619</guid>
		<description><![CDATA[<p>Wenn man am PC sitzt vergisst man schnell die Zeit. Wenn man noch etwas erledigen muss wäre es daher vorteilhaft, wenn man daran erinnert werden würde. </p>
<p>Ein solches &#8220;Erinnerungsprogramm&#8221; kann man sich recht leicht selber basteln. Ich habe dafür  das Linuxtool <code>at</code> mit dem Programm <a href="http://wiki.ubuntuusers.de/Zenity" target="_blank" title="zenity - Darstellung von Dialogen" class="liuu"><code>zenity</code></a>, welches Dialoge darstellen kann, kombiniert.&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Wenn man am PC sitzt vergisst man schnell die Zeit. Wenn man noch etwas erledigen muss wäre es daher vorteilhaft, wenn man daran erinnert werden würde. </p>
<p>Ein solches &#8220;Erinnerungsprogramm&#8221; kann man sich recht leicht selber basteln. Ich habe dafür  das Linuxtool <code>at</code> mit dem Programm <a href="http://wiki.ubuntuusers.de/Zenity" target="_blank" title="zenity - Darstellung von Dialogen" class="liuu"><code>zenity</code></a>, welches Dialoge darstellen kann, kombiniert.</p>
<p><code>at</code> (bzw. der at-Daemon <code>atd</code>) ist auf den meisten Linuxdistributionen bereits vorhanden, kann sonst aber auch über die Paketverwaltung installiert werden. Zenity sollte bei den meisten Distributionen ebenfalls über die Paketverwaltung installierbar sein.<br />
Unter Ubuntu installiert man <code>zenity</code> mit dem Befehl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> zenity</pre></div></div>

<p>Mit <code>at</code> können Befehle zu einem festgelegten Zeitpunkt ausgeführt werden. Eine sehr schöne Einführung gibt es in der <a href="http://www.freiesmagazin.de/mobil/freiesMagazin-2008-10-bilder.html#08_10_at" target="_blank" title="freiesMagazin 10/2008 - at" class="liexternal">Ausgabe 10/2008 von freiesMagazin</a> (eine Fortsetzung ist in der <a href="http://www.freiesmagazin.de/mobil/freiesMagazin-2008-11-bilder.html#08_11_at-beispiele" target="_blank" class="liexternal">nachfolgenden Ausgabe</a> enthalten, welche mich auch zu diesem &#8220;Programm&#8221; inspirierte, weil ich mit den dort vorgestellten Erinnerungs-Lösungen nicht zufrieden war).</p>
<p>Um mit <code>zenity</code> einen Dialog anzuzeigen kann man folgenden Befehl nutzen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zenity <span style="color: #660033;">--info</span> <span style="color: #660033;">--title</span>=<span style="color: #ff0000;">&quot;Titel des Dialogs&quot;</span> <span style="color: #660033;">--text</span> <span style="color: #ff0000;">&quot;Text, der angezeigt werden soll&quot;</span></pre></div></div>

<p>Damit dies von <code>at</code> angezeigt werden kann muss noch das Display angegeben werden:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">zenity <span style="color: #660033;">--info</span> <span style="color: #660033;">--title</span>=<span style="color: #ff0000;">&quot;Titel des Dialogs&quot;</span> <span style="color: #660033;">--text</span> <span style="color: #ff0000;">&quot;Text, der angezeigt werden soll&quot;</span> <span style="color: #660033;">--display</span>=:<span style="color: #000000;">0</span></pre></div></div>

<p>Diesen Befehl kann man nun in ein Bash- oder Perl-Script einfügen, wobei der Titel fest sein kann und der Text als Argument übergeben wird. Ich habe mich für Perl entschieden:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000066;">system</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;zenity --info --title=<span style="color: #000099; font-weight: bold;">\&quot;</span>Erinnerung<span style="color: #000099; font-weight: bold;">\&quot;</span> --text <span style="color: #000099; font-weight: bold;">\&quot;</span>@ARGV<span style="color: #000099; font-weight: bold;">\&quot;</span> --display=:0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Dieses Script habe ich unter dem Namen <code>r</code> (für &#8220;remember&#8221;) im bin-Ordner meines Homeverzeichnisses gespeichert. Dieses muss natürlich im Pfad liegen, was durch folgende Zeile in der Datei <code>~/.bashrc</code> erreicht werden kann:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>user<span style="color: #000000; font-weight: bold;">/</span>bin</pre></div></div>

<p>&#8220;user&#8221; muss natürlich durch den entsprechenden Usernamen ersetzt werden. Nachdem man die <code>~/.bashrc</code> mit dem Befehl</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">. ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>

<p>neu &#8220;geladen&#8221; hat kann man sich nun an Termine oder andere Dinge erinnern lassen.</p>
<p><strong>Beispiele:</strong><br />
Um 14:30 Termin bei FooBar. Also um 14:15 erinnern:</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">at 14:15
r Termin bei FooBar in 15 Minuten
Strg+d</pre></div></div>

<p>In einer halben Stunde ist eine Besprechung (5 min vorher erinnern):</p>

<div class="wp_syntax"><div class="code"><pre class="plain" style="font-family:monospace;">at now +25min
r Besprechung
Strg+d</pre></div></div>

<p>Es öffnet sich zur angegebenen Zeit ein Dialogfenster (egal, was man gerade macht &#8211; solange man sich in X befindet. Bei Spielen im Fullscreen habe ich es jedoch nicht getestet.), welches den Titel &#8220;Erinnerung&#8221; enthält und den angegebenen Text ausgibt. Das Fenster kann durch einen Klick auf &#8220;OK&#8221; wieder geschlossen werden.</p>
<p><code>at</code> bietet noch viele weitere Möglichkeiten eine Zeit anzugeben. Diese werden im (ersten) oben verlinkten freiesMagazin-Artikel beschrieben.</p>
]]></content:encoded>
			<wfw:commentRss>http://zinformatik.de/linux/erinnerungen-mit-at-und-zenity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Titel von Screen-Fenstern automatisch von Vim, Bash und zsh setzen</title>
		<link>http://zinformatik.de/linux/titel-von-screen-fenstern-automatisch-von-vim-bash-und-zsh-setzen/</link>
		<comments>http://zinformatik.de/linux/titel-von-screen-fenstern-automatisch-von-vim-bash-und-zsh-setzen/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 09:34:51 +0000</pubDate>
		<dc:creator>zimon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntuusers-Planet]]></category>
		<category><![CDATA[vim Tipps]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Konsole]]></category>
		<category><![CDATA[Screen]]></category>
		<category><![CDATA[Titel]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://zinformatik.de/?p=1605</guid>
		<description><![CDATA[<p>Wenn man unter <a href="http://zinformatik.de/tipps-tricks/interessante-programme/einfuhrung-in-screen/" title="Einführung in Screen" target="_blank" class="liinternal">Screen</a> die Statusleiste nutzt, ist es oft mühsam jedes mal die Titel zu setzen. Auch wenn man diese fest in der <code>~/.screenrc</code> definiert, kann man manchmal durcheinander kommen.</p>
<p>Unter Vim gibt es die Möglichkeit, den Namen der aktuellen Datei als Titel für das Screenfenster zu benutzen.<br />
Dafür braucht man nur&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Wenn man unter <a href="http://zinformatik.de/tipps-tricks/interessante-programme/einfuhrung-in-screen/" title="Einführung in Screen" target="_blank" class="liinternal">Screen</a> die Statusleiste nutzt, ist es oft mühsam jedes mal die Titel zu setzen. Auch wenn man diese fest in der <code>~/.screenrc</code> definiert, kann man manchmal durcheinander kommen.</p>
<p>Unter Vim gibt es die Möglichkeit, den Namen der aktuellen Datei als Titel für das Screenfenster zu benutzen.<br />
Dafür braucht man nur die folgenden Zeilen zur <code>~/.vimrc</code> hinzufügen:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">if</span> <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'$TERM'</span><span style="color: #000000;">&#41;</span> == <span style="color: #C5A22D;">'screen'</span>
<span style="color: #804040;">augroup</span> vim_screen
  <span style="color: #804040;">autocmd</span><span style="color: #000000;">!</span>
  <span style="color: #804040;">autocmd</span> <span style="color: #25BB4D;">VimEnter</span>,<span style="color: #25BB4D;">BufWinEnter</span>,<span style="color: #25BB4D;">WinEnter</span> <span style="color: #000000;">*</span>
    \ <span style="color: #804040;">exec</span> <span style="color: #C5A22D;">&quot;silent! !echo -ne '<span style="">\\</span>ek&quot;</span> <span style="color: #000000;">.</span> <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'%:t'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;<span style="">\\</span>e<span style="">\\</span><span style="">\\</span>'&quot;</span>
<span style="color: #804040;">augroup</span> END
<span style="color: #804040;">endif</span></pre></div></div>

<p><strong>[UPDATE]</strong>Auf dem <a href="http://blog.256bit.org/archives/451-Vim-in-Screen.html" title="Vim in Screen" target="_blank" class="liexternal">256bit Blog</a> beschreibt Christian Brabandt, wie man den Screen-Titel von Vim aus ohne autocommands und mit sehr vielen Einstellungen setzen kann.<strong>[/UPDATE]</strong></p>
<p>Ansonsten finde ich es sehr praktisch, wenn in der Statusleiste das aktuelle Verzeichnis steht. Da der komplette Pfad meist sehr lang ist, können mit einem regulären Ausdruck alle Verzeichnisse bis auf das letzte jeweils mit ihren Anfangsbuchstaben abgekürzt werden:</p>
<p><code>s/(\w).*?\//$1\//g</code></p>
<p>So wird <code>/home/zimon/.vim/plugin</code> zu <code>/h/z/.v/plugin</code> abgekürzt.</p>
<p>Wem das immer noch zu lang ist, der kann aus dem Namen des letzten Verzeichnisses auch noch die Vokale heraus nehmen (ähnlich wie es dillo in seinen Tabs macht):</p>
<p><code>s/(\w).*?\//$1\//g; my $end; $x=~s/\/(.)(?:[aeiou]|([^aeiou\/])(?{$end.=$^N}))*\s*$/\/$1$end/</code></p>
<p>Damit wird <code>/home/zimon/.vim/plugin</code> zu <code>/h/z/.v/plgn</code></p>
<p>Um in der Bash den Screen-Titel automatisch zu setzen, kann man folgenden Code zu seiner <code>~/.bashrc</code> hinzufügen. Hier wurde der erste reguläre Ausdruck genutzt (man kann ihn natürlich auch durch den anderen Ausdruck ersetzen, wenn man möchte):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> precmd <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        <span style="color: #c20cb9; font-weight: bold;">screen</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #007800;">wd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'$x=shift; $x=~ s/(\w).*?\//$1\//g; print $x;'</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PWD</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-ne</span> <span style="color: #ff0000;">&quot;\033k<span style="color: #007800;">$wd</span>\033\<span style="color: #000099; font-weight: bold;">\&quot;</span>
        ;;
    esac
}
PROMPT_COMMAND=precmd</span></pre></div></div>

<p>Für zsh User gibt es hier den Code für die <code>~/.zshrc</code>. In diesem Beispiel wurde der zweite reguläre Ausdruck genutzt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> precmd <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$TERM</span>&quot;</span> == <span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">local</span> <span style="color: #007800;">wd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'$x=shift; $ x=~ s/(\w).*?\//$1\//g; my $end; $x=~s/\/(.)(?:[aeiou]|([^aeiou\/])(?{$end.=$^N}))*\s*$/\/$1$end/; print $x;'</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PWD</span>&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">PR_STITLE</span>=$<span style="color: #ff0000;">'%{\ek'</span><span style="color: #007800;">$wd</span>$<span style="color: #ff0000;">'\e\\%}'</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Vielen Dank an <a href="http://zinformatik.de/author/ploppor/" target="_self" class="liinternal">Ploppor</a> für den zsh Code und sonstige zahlreiche Unterstützung in letzter Zeit.</p>
<p>Es tut mir leid, dass ich in letzter Zeit nichts geschrieben habe, aber meine Diplomarbeit lässt mir einfach keine Zeit.</p>
]]></content:encoded>
			<wfw:commentRss>http://zinformatik.de/linux/titel-von-screen-fenstern-automatisch-von-vim-bash-und-zsh-setzen/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Praktische alias-Kommandos für die Bash</title>
		<link>http://zinformatik.de/linux/praktische-alias-kommandos-fur-die-bash/</link>
		<comments>http://zinformatik.de/linux/praktische-alias-kommandos-fur-die-bash/#comments</comments>
		<pubDate>Sun, 17 May 2009 17:14:12 +0000</pubDate>
		<dc:creator>zimon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntuusers-Planet]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Konsole]]></category>

		<guid isPermaLink="false">http://zinformatik.de/?p=1235</guid>
		<description><![CDATA[<p>Sehr praktisch bei der Bash ist die Möglichkeit sich alias-Befehle zu konfigurieren. Damit kann man bestehende Befehle überschreiben oder Abkürzungen hinzufügen. Ich habe mal einige praktische alias-Kommandos zusammen gestellt. Es wären natürlich noch viel mehr denkbar, aber vielleicht regen die hier genannten ja beim einen oder anderen die Phantasie an.</p>
<p>Übrigens kann man die &#8220;Ursprungsversion&#8221; eines Kommandos, welches durch einen&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Sehr praktisch bei der Bash ist die Möglichkeit sich alias-Befehle zu konfigurieren. Damit kann man bestehende Befehle überschreiben oder Abkürzungen hinzufügen. Ich habe mal einige praktische alias-Kommandos zusammen gestellt. Es wären natürlich noch viel mehr denkbar, aber vielleicht regen die hier genannten ja beim einen oder anderen die Phantasie an.</p>
<p>Übrigens kann man die &#8220;Ursprungsversion&#8221; eines Kommandos, welches durch einen Alias überschrieben wurde durch ein Vorrangestelltes <em>\</em> aufrufen. Also wenn es z.B. folgenden alias gibt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ls</span>=<span style="color: #ff0000;">&quot;ls --color=auto&quot;</span></pre></div></div>

<p>so kann man durch die Eingabe von</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">\<span style="color: #c20cb9; font-weight: bold;">ls</span></pre></div></div>

<p>den Befehl <em>ls</em> ohne <em>&#8211;color=auto</em> aufrufen.</p>
<p><strong>Grundlegende Kommandos im Dateisystem</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Macht die Ausgabe von ls farbig:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ls</span>=<span style="color: #ff0000;">'ls --color=auto'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Gibt zu jeder Datei weitere Informationen aus. Größenangaben immer &quot;menschenlich lesbar&quot;:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ll</span>=<span style="color: #ff0000;">'ls -lh'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Wie ll, aber es werden auch versteckte Dateien aufgelistet:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">la</span>=<span style="color: #ff0000;">'ls -lha'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Für Vertipper recht praktisch:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> cd..=<span style="color: #ff0000;">'cd ..'</span> 
<span style="color: #7a0874; font-weight: bold;">alias</span> cd-=<span style="color: #ff0000;">'cd -'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Abkürzung für cd .. :</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> ..=<span style="color: #ff0000;">'cd ..'</span> 
<span style="color: #7a0874; font-weight: bold;">alias</span> ...=<span style="color: #ff0000;">'cd ../..'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Alle nicht existierenden Verzeichnisse automatisch erstellen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mkdir</span>=<span style="color: #ff0000;">'mkdir -p'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Für Anfänger zu empfehlen (es wird bei jeder Datei nachgefragt)</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">rm</span>=<span style="color: #ff0000;">'rm -i'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">cp</span>=<span style="color: #ff0000;">'cp -i'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mv</span>=<span style="color: #ff0000;">'mv -i'</span></pre></div></div>

<p><strong>Befehle die immer mit bestimmten Optionen ausgeführt werden sollen sowie Abkürzungen</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Bei df die Größen immer &quot;menschlich lesbar&quot; anzeigen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">df</span>=<span style="color: #ff0000;">'df -h'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Bei du die Größen immer &quot;menschlich lesbar&quot; anzeigen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">du</span>=<span style="color: #ff0000;">'du -h'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Suche in less case-insensitive:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">l</span>=<span style="color: #ff0000;">'less -i'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Zeigt Änderungen einer Datei an (wie tail -f):</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lf</span>=<span style="color: #ff0000;">'less -i +F'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Beispielhafte Abkürzung für ssh</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">meinserver</span>=<span style="color: #ff0000;">'ssh user@meinserver.tld'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># lässt grep case-insensitive arbeiten und markiert die Treffer farbig:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">grep</span>=<span style="color: #ff0000;">'grep -i --color=auto'</span></pre></div></div>

<p>Die Follow-Option von <em>less</em> (<em>less +F</em>) ist recht praktisch, da sie einfach mit Strg+c unterbrochen und mit F weitergeführt werden kann. So kann man leicht nochmal zurück scrollen.</p>
<p><strong>Befehle zum Suchen, Installieren und Updaten</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Da apt-get ja meist mit sudo aufgerufen wird:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> apt-get=<span style="color: #ff0000;">'sudo apt-get'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">#Statt dessen kann man auch die folgenden Befehle nutzen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">agi</span>=<span style="color: #ff0000;">'sudo apt-get install'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">acs</span>=<span style="color: #ff0000;">'apt-cache search'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Das ganze System updaten:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">update</span>=<span style="color: #ff0000;">'sudo apt-get update &amp;&amp; sudo apt-get upgrade'</span></pre></div></div>

<p><strong>Komplexere Befehle</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Starte Kommando in neuem Screen-Fenster:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">s</span>=<span style="color: #ff0000;">'screen -X screen'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Dateinamen im aktuellen Verzeichnis nach Ausdruck durchsuchen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lg</span>=<span style="color: #ff0000;">'ls --color=always | grep --color=always -i'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Timestamp generieren:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">timestamp</span>=<span style="color: #ff0000;">'date &quot;+%Y%m%d%H%M%S&quot;'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Verzeichnis mit aktuellem Timestamp erstellen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">tsdir</span>=<span style="color: #ff0000;">'timestamp | xargs mkdir'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Änderungen bei allen angegebenen Logdateien live anzeigen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mylogs</span>=<span style="color: #ff0000;">'sudo tail -f /var/log/{syslog,messages}'</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Einen Prozess (nach Namen) suchen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">psg</span>=<span style="color: #ff0000;">'ps ax | grep -v grep | grep '</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Die öffentliche IP ausgeben:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">myip</span>=<span style="color: #ff0000;">&quot;wget -qO - http://checkip.dyndns.org | sed 's/[a-zA-Z&lt;&gt;/ :]//g'&quot;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Zuletzt bearbeitete Datei in vim öffnen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lvim</span>=<span style="color: #ff0000;">&quot;vim -c <span style="color: #000099; font-weight: bold;">\&quot;</span>normal '0<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;"># Die 10 Prozesse anzeigen, die den meisten RAM verbrauchen:</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">psram</span>=<span style="color: #ff0000;">'ps aux | sort -rnk 4 | head'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Zeige alle Prozesse bei ps (außer ps selbst) mit langer Ausgabe</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">ps</span>=<span style="color: #ff0000;">'ps ax | grep -v &quot;ps ax&quot;'</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://zinformatik.de/linux/praktische-alias-kommandos-fur-die-bash/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Tipps und Tricks für die Bash</title>
		<link>http://zinformatik.de/linux/tipps-und-tricks-fur-die-bash/</link>
		<comments>http://zinformatik.de/linux/tipps-und-tricks-fur-die-bash/#comments</comments>
		<pubDate>Sun, 10 May 2009 17:12:03 +0000</pubDate>
		<dc:creator>zimon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tipps und Tricks]]></category>
		<category><![CDATA[Ubuntuusers-Planet]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[History]]></category>
		<category><![CDATA[Konsole]]></category>
		<category><![CDATA[Prozesse]]></category>

		<guid isPermaLink="false">http://zinformatik.de/?p=1194</guid>
		<description><![CDATA[<p>Hier ein paar kleine Tipps und Tricks für die Bash.</p>
<p><strong>Livesuche in der History</strong><br />
Sucht man ein Kommando, welches man schon einmal eingegeben hat, so kann man die History (welche in der Datei ~/.bash_history gespeichert wird) durchsuchen. Die Bash stellt dafür sogar eine Livesuche bereit. Diese wird mit der Tastenkombination Strg+r eingeleitet. Danach kann man eine beliebige Zeichenkette eingeben, die&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Hier ein paar kleine Tipps und Tricks für die Bash.</p>
<p><strong>Livesuche in der History</strong><br />
Sucht man ein Kommando, welches man schon einmal eingegeben hat, so kann man die History (welche in der Datei ~/.bash_history gespeichert wird) durchsuchen. Die Bash stellt dafür sogar eine Livesuche bereit. Diese wird mit der Tastenkombination Strg+r eingeleitet. Danach kann man eine beliebige Zeichenkette eingeben, die in irgendeinem Befehl schonmal vorgekommen ist. Mit jedem eingegebenen Buchstaben werden Vorschläge gemacht, wobei die Suche immer Rückwärts läuft.<br />
Durch erneutes Drücken von Strg+r kann man weiter suchen. So kann man dann z.b. mit <em>Strg+r sudo Strg+r</em> zum vorletzten <em>sudo</em>-Befehl gelangen.</p>
<p><strong>Weitere History-Funktionen</strong><br />
Mit dem Befehl <em>history</em> werden alle eingegebenen Kommandos, die sich in der History befinden mit Zeilennummer ausgegeben. Gibt man dem Befehl noch eine Zahl x als Parameter mit, so werden nur die letzten x Einträge angezeigt. Mit der Option -c (clear) kann man die History löschen.<br />
Normalerweise wird die Datei ~/.bash_history erst beim beenden der Shell geschrieben. Man kann sie aber auch sofort schreiben, indem man den Befehl <em>history -w</em> ausführt. Umgekehrt kann man die aktuelle History auch mittels <em>history -r</em> aus der Datei ~/.bash_history einlesen.</p>
<p><strong>Praktische Tastenkombinationen</strong></p>
<ul>
<li>Strg+l &#8211; (kleines L) löscht den Bildschirm</li>
<li>Strg+u &#8211; löscht alles vor dem Cursor</li>
<li>Strg+t &#8211; tauscht die letzten beiden Zeichen</li>
<li>Alt+. &#8211; fügt das letzte Argument ein</li>
<li>Strg+d &#8211; beendet die Sitzung bzw. sendet ein EOF (z.B. für at).</li>
</ul>
<p><strong>Praktische Variablen</strong></p>
<ul>
<li>!! &#8211; kompletter letzter eingegebener Befehl</li>
<li>!$ &#8211; letztes Argument</li>
<li>$$ &#8211; PID der aktuellen Bash</li>
<li>!String &#8211; letztes Kommando, das mit <em>String</em> angefangen hat</li>
<li>!?String &#8211; letztes Kommando, welches <em>String</em> enthielt.</li>
</ul>
<p>So kann man mit <em>sudo !!</em> den letzten Befehl mit root-Rechten erneut ausführen oder ihn mit <em>echo &#8220;!!&#8221; > script.sh</em> in eine Datei schreiben.<br />
Nach einem Kopierbefehl wechselt man mit <em>cd !$</em> in das Verzeichnis, wohin die Datei(en) kopiert wurde(n).<br />
Mit <em>kill -9 $$</em> wird die Bash geschlossen ohne dass die Historydatei geschrieben werden kann.</p>
<p><strong>vi-Modus</strong><br />
Die Bash beinhaltet einen vi-Modus, wodurch man vi-Befehle in der Bash nutzen kann. Den Modus startet man mittels</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-o</span> <span style="color: #c20cb9; font-weight: bold;">vi</span></pre></div></div>

<p>Danach kann man mit ESC in den Kommandomodus gelangen und mit hjkl statt Pfeiltasten navigieren. auch dd, D , p , A, 0 und $,&#8230; funktionieren.<br />
Die obige Zeile kann man sich auch in die ~/.bashrc schreiben, damit der vi-Modus standardmäßig aktiviert ist.<br />
Leider funktioniert danach die Tastenkombination Strg+l nicht mehr. Diese kann man jedoch mit einem Binding wieder aktivieren. Dafür schreibt man folgendes in die ~/.bashrc:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Strg+l - clear screen</span>
<span style="color: #7a0874; font-weight: bold;">bind</span> <span style="color: #660033;">-m</span> vi-insert <span style="color: #ff0000;">&quot;\C-l&quot;</span>:clear-screen</pre></div></div>

<p><strong>Geänderte Konfigurationsdatei einlesen ohne neues Terminal aufzumachen</strong><br />
kann man mit folgendem Befehl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">source</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc</pre></div></div>

<p><strong>Prozesskontrolle</strong><br />
Um ein Programm im Hintergrund zu starten hängt man dem Befehl ein <em>&#038;</em> an.<br />
Hat man dies vergessen, so kann man das Programm mit Strg+z anhalten, wodurch man wieder einen Prompt bekommt. Dann kann man den Prozess mittels <em>bg</em> im Hintergrund weiterlaufen lassen. Um ihn wieder in den Vordergrund zu holen genügt ein <em>fg</em>.<br />
Wenn mehrere Prozesse im Hintergrund laufen, so holt <em>fg</em> den letzten Prozess zurück, der in den Hintergrund geschickt wurde. Möchte man einen anderen Prozess in den Vordergrund holen, so kann man <em>fg</em> die entsprechende Job-ID (diese steht in Eckigen klammern, wenn ein Prozess gestoppt oder in den Hintergrund verschoben wird) als Argument mitgeben. Alternativ kann man als Paramter für <em>fg</em> ein <em>%</em> gefolgt von einigen Anfangsbuchstaben des Befehls mitgeben.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">fg</span> <span style="color: #000000; font-weight: bold;">%</span>v</pre></div></div>

<p>holt zum Beispiel einen vim-Prozess aus dem Hintergrund (wenn keine anderen Prozesse mit v im Hintergrund sind).</p>
<p>Um zwei Befehle nacheinander auszuführen, kann man sie mit einem Semikolon trennen. Möchte man, dass der 2. Befehl nur ausgeführt wird, wenn der erste Befehl erfolgreich war, so trennt man sie mit <em>&#038;&#038;</em>. dies ist praktisch beim compilieren von Programmen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>So wird <em>make</em> nur ausgeführt, wenn das configurescript ohne Fehler durchgelaufen ist. <em>make install</em> wird nur ausgeführt, wenn <em>make</em> auch wirklich compiliert hat.</p>
]]></content:encoded>
			<wfw:commentRss>http://zinformatik.de/linux/tipps-und-tricks-fur-die-bash/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

