1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
5 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
\r
6 <meta name="generator" content="AsciiDoc 8.6.9" />
\r
7 <title>ZSH-LOVERS(1)</title>
\r
8 <style type="text/css">
\r
9 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
\r
13 font-family: Georgia,serif;
\r
17 h1, h2, h3, h4, h5, h6,
\r
18 div.title, caption.title,
\r
19 thead, p.table.header,
\r
21 #author, #revnumber, #revdate, #revremark,
\r
23 font-family: Arial,Helvetica,sans-serif;
\r
27 margin: 1em 5% 1em 5%;
\r
32 text-decoration: underline;
\r
48 h1, h2, h3, h4, h5, h6 {
\r
51 margin-bottom: 0.5em;
\r
56 border-bottom: 2px solid silver;
\r
76 border: 1px solid silver;
\r
81 margin-bottom: 0.5em;
\r
87 ul > li { color: #aaa; }
\r
88 ul > li > * { color: black; }
\r
90 .monospaced, code, pre {
\r
91 font-family: "Courier New", Courier, monospace;
\r
98 white-space: pre-wrap;
\r
108 #revnumber, #revdate, #revremark {
\r
113 border-top: 2px solid silver;
\r
114 padding-top: 0.5em;
\r
119 padding-bottom: 0.5em;
\r
123 padding-bottom: 0.5em;
\r
128 margin-bottom: 1.5em;
\r
130 div.imageblock, div.exampleblock, div.verseblock,
\r
131 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
132 div.admonitionblock {
\r
134 margin-bottom: 1.5em;
\r
136 div.admonitionblock {
\r
138 margin-bottom: 2.0em;
\r
143 div.content { /* Block element content. */
\r
147 /* Block element titles. */
\r
148 div.title, caption.title {
\r
153 margin-bottom: 0.5em;
\r
159 td div.title:first-child {
\r
162 div.content div.title:first-child {
\r
165 div.content + div.title {
\r
169 div.sidebarblock > div.content {
\r
170 background: #ffffee;
\r
171 border: 1px solid #dddddd;
\r
172 border-left: 4px solid #f0f0f0;
\r
176 div.listingblock > div.content {
\r
177 border: 1px solid #dddddd;
\r
178 border-left: 5px solid #f0f0f0;
\r
179 background: #f8f8f8;
\r
183 div.quoteblock, div.verseblock {
\r
184 padding-left: 1.0em;
\r
185 margin-left: 1.0em;
\r
187 border-left: 5px solid #f0f0f0;
\r
191 div.quoteblock > div.attribution {
\r
192 padding-top: 0.5em;
\r
196 div.verseblock > pre.content {
\r
197 font-family: inherit;
\r
198 font-size: inherit;
\r
200 div.verseblock > div.attribution {
\r
201 padding-top: 0.75em;
\r
204 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
\r
205 div.verseblock + div.attribution {
\r
209 div.admonitionblock .icon {
\r
210 vertical-align: top;
\r
213 text-decoration: underline;
\r
215 padding-right: 0.5em;
\r
217 div.admonitionblock td.content {
\r
218 padding-left: 0.5em;
\r
219 border-left: 3px solid #dddddd;
\r
222 div.exampleblock > div.content {
\r
223 border-left: 3px solid #dddddd;
\r
224 padding-left: 0.5em;
\r
227 div.imageblock div.content { padding-left: 0; }
\r
228 span.image img { border-style: none; vertical-align: text-bottom; }
\r
229 a.image:visited { color: white; }
\r
233 margin-bottom: 0.8em;
\r
238 font-style: normal;
\r
241 dd > *:first-child {
\r
246 list-style-position: outside;
\r
249 list-style-type: decimal;
\r
252 list-style-type: lower-alpha;
\r
255 list-style-type: upper-alpha;
\r
258 list-style-type: lower-roman;
\r
261 list-style-type: upper-roman;
\r
264 div.compact ul, div.compact ol,
\r
265 div.compact p, div.compact p,
\r
266 div.compact div, div.compact div {
\r
268 margin-bottom: 0.1em;
\r
280 margin-bottom: 0.8em;
\r
283 padding-bottom: 15px;
\r
285 dt.hdlist1.strong, td.hdlist1.strong {
\r
289 vertical-align: top;
\r
290 font-style: normal;
\r
291 padding-right: 0.8em;
\r
295 vertical-align: top;
\r
297 div.hdlist.compact tr {
\r
303 background: yellow;
\r
306 .footnote, .footnoteref {
\r
310 span.footnote, span.footnoteref {
\r
311 vertical-align: super;
\r
315 margin: 20px 0 20px 0;
\r
316 padding: 7px 0 0 0;
\r
319 #footnotes div.footnote {
\r
325 border-top: 1px solid silver;
\r
334 padding-right: 0.5em;
\r
335 padding-bottom: 0.3em;
\r
336 vertical-align: top;
\r
338 div.colist td img {
\r
343 #footer-badges { display: none; }
\r
347 margin-bottom: 2.5em;
\r
355 margin-bottom: 0.1em;
\r
358 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
\r
375 span.aqua { color: aqua; }
\r
376 span.black { color: black; }
\r
377 span.blue { color: blue; }
\r
378 span.fuchsia { color: fuchsia; }
\r
379 span.gray { color: gray; }
\r
380 span.green { color: green; }
\r
381 span.lime { color: lime; }
\r
382 span.maroon { color: maroon; }
\r
383 span.navy { color: navy; }
\r
384 span.olive { color: olive; }
\r
385 span.purple { color: purple; }
\r
386 span.red { color: red; }
\r
387 span.silver { color: silver; }
\r
388 span.teal { color: teal; }
\r
389 span.white { color: white; }
\r
390 span.yellow { color: yellow; }
\r
392 span.aqua-background { background: aqua; }
\r
393 span.black-background { background: black; }
\r
394 span.blue-background { background: blue; }
\r
395 span.fuchsia-background { background: fuchsia; }
\r
396 span.gray-background { background: gray; }
\r
397 span.green-background { background: green; }
\r
398 span.lime-background { background: lime; }
\r
399 span.maroon-background { background: maroon; }
\r
400 span.navy-background { background: navy; }
\r
401 span.olive-background { background: olive; }
\r
402 span.purple-background { background: purple; }
\r
403 span.red-background { background: red; }
\r
404 span.silver-background { background: silver; }
\r
405 span.teal-background { background: teal; }
\r
406 span.white-background { background: white; }
\r
407 span.yellow-background { background: yellow; }
\r
409 span.big { font-size: 2em; }
\r
410 span.small { font-size: 0.6em; }
\r
412 span.underline { text-decoration: underline; }
\r
413 span.overline { text-decoration: overline; }
\r
414 span.line-through { text-decoration: line-through; }
\r
416 div.unbreakable { page-break-inside: avoid; }
\r
426 margin-bottom: 1.5em;
\r
428 div.tableblock > table {
\r
429 border: 3px solid #527bbd;
\r
431 thead, p.table.header {
\r
438 /* Because the table frame attribute is overriden by CSS in most browsers. */
\r
439 div.tableblock > table[frame="void"] {
\r
440 border-style: none;
\r
442 div.tableblock > table[frame="hsides"] {
\r
443 border-left-style: none;
\r
444 border-right-style: none;
\r
446 div.tableblock > table[frame="vsides"] {
\r
447 border-top-style: none;
\r
448 border-bottom-style: none;
\r
459 margin-bottom: 1.5em;
\r
461 thead, p.tableblock.header {
\r
470 border-spacing: 0px;
\r
471 border-style: solid;
\r
472 border-color: #527bbd;
\r
473 border-collapse: collapse;
\r
475 th.tableblock, td.tableblock {
\r
478 border-style: solid;
\r
479 border-color: #527bbd;
\r
482 table.tableblock.frame-topbot {
\r
483 border-left-style: hidden;
\r
484 border-right-style: hidden;
\r
486 table.tableblock.frame-sides {
\r
487 border-top-style: hidden;
\r
488 border-bottom-style: hidden;
\r
490 table.tableblock.frame-none {
\r
491 border-style: hidden;
\r
494 th.tableblock.halign-left, td.tableblock.halign-left {
\r
497 th.tableblock.halign-center, td.tableblock.halign-center {
\r
498 text-align: center;
\r
500 th.tableblock.halign-right, td.tableblock.halign-right {
\r
504 th.tableblock.valign-top, td.tableblock.valign-top {
\r
505 vertical-align: top;
\r
507 th.tableblock.valign-middle, td.tableblock.valign-middle {
\r
508 vertical-align: middle;
\r
510 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
\r
511 vertical-align: bottom;
\r
521 padding-top: 0.5em;
\r
522 padding-bottom: 0.5em;
\r
523 border-top: 2px solid silver;
\r
524 border-bottom: 2px solid silver;
\r
527 border-style: none;
\r
529 body.manpage div.sectionbody {
\r
534 body.manpage div#toc { display: none; }
\r
539 <script type="text/javascript">
\r
541 var asciidoc = { // Namespace.
\r
543 /////////////////////////////////////////////////////////////////////
\r
544 // Table Of Contents generator
\r
545 /////////////////////////////////////////////////////////////////////
\r
547 /* Author: Mihai Bazon, September 2002
\r
548 * http://students.infoiasi.ro/~mishoo
\r
550 * Table Of Content generator
\r
553 * Feel free to use this script under the terms of the GNU General Public
\r
554 * License, as long as you do not remove or alter this notice.
\r
557 /* modified by Troy D. Hanson, September 2006. License: GPL */
\r
558 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
\r
560 // toclevels = 1..4.
\r
561 toc: function (toclevels) {
\r
563 function getText(el) {
\r
565 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
566 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
\r
568 else if (i.firstChild != null)
\r
569 text += getText(i);
\r
574 function TocEntry(el, text, toclevel) {
\r
577 this.toclevel = toclevel;
\r
580 function tocEntries(el, toclevels) {
\r
581 var result = new Array;
\r
582 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
\r
583 // Function that scans the DOM tree for header elements (the DOM2
\r
584 // nodeIterator API would be a better technique but not supported by all
\r
586 var iterate = function (el) {
\r
587 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
588 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
\r
589 var mo = re.exec(i.tagName);
\r
590 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
\r
591 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
\r
601 var toc = document.getElementById("toc");
\r
606 // Delete existing TOC entries in case we're reloading the TOC.
\r
607 var tocEntriesToRemove = [];
\r
609 for (i = 0; i < toc.childNodes.length; i++) {
\r
610 var entry = toc.childNodes[i];
\r
611 if (entry.nodeName.toLowerCase() == 'div'
\r
612 && entry.getAttribute("class")
\r
613 && entry.getAttribute("class").match(/^toclevel/))
\r
614 tocEntriesToRemove.push(entry);
\r
616 for (i = 0; i < tocEntriesToRemove.length; i++) {
\r
617 toc.removeChild(tocEntriesToRemove[i]);
\r
620 // Rebuild TOC entries.
\r
621 var entries = tocEntries(document.getElementById("content"), toclevels);
\r
622 for (var i = 0; i < entries.length; ++i) {
\r
623 var entry = entries[i];
\r
624 if (entry.element.id == "")
\r
625 entry.element.id = "_toc_" + i;
\r
626 var a = document.createElement("a");
\r
627 a.href = "#" + entry.element.id;
\r
628 a.appendChild(document.createTextNode(entry.text));
\r
629 var div = document.createElement("div");
\r
630 div.appendChild(a);
\r
631 div.className = "toclevel" + entry.toclevel;
\r
632 toc.appendChild(div);
\r
634 if (entries.length == 0)
\r
635 toc.parentNode.removeChild(toc);
\r
639 /////////////////////////////////////////////////////////////////////
\r
640 // Footnotes generator
\r
641 /////////////////////////////////////////////////////////////////////
\r
643 /* Based on footnote generation code from:
\r
644 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
\r
647 footnotes: function () {
\r
648 // Delete existing footnote entries in case we're reloading the footnodes.
\r
650 var noteholder = document.getElementById("footnotes");
\r
654 var entriesToRemove = [];
\r
655 for (i = 0; i < noteholder.childNodes.length; i++) {
\r
656 var entry = noteholder.childNodes[i];
\r
657 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
\r
658 entriesToRemove.push(entry);
\r
660 for (i = 0; i < entriesToRemove.length; i++) {
\r
661 noteholder.removeChild(entriesToRemove[i]);
\r
664 // Rebuild footnote entries.
\r
665 var cont = document.getElementById("content");
\r
666 var spans = cont.getElementsByTagName("span");
\r
669 for (i=0; i<spans.length; i++) {
\r
670 if (spans[i].className == "footnote") {
\r
672 var note = spans[i].getAttribute("data-note");
\r
674 // Use [\s\S] in place of . so multi-line matches work.
\r
675 // Because JavaScript has no s (dotall) regex flag.
\r
676 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
\r
677 spans[i].innerHTML =
\r
678 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
\r
679 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
680 spans[i].setAttribute("data-note", note);
\r
682 noteholder.innerHTML +=
\r
683 "<div class='footnote' id='_footnote_" + n + "'>" +
\r
684 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
\r
685 n + "</a>. " + note + "</div>";
\r
686 var id =spans[i].getAttribute("id");
\r
687 if (id != null) refs["#"+id] = n;
\r
691 noteholder.parentNode.removeChild(noteholder);
\r
693 // Process footnoterefs.
\r
694 for (i=0; i<spans.length; i++) {
\r
695 if (spans[i].className == "footnoteref") {
\r
696 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
\r
697 href = href.match(/#.*/)[0]; // Because IE return full URL.
\r
699 spans[i].innerHTML =
\r
700 "[<a href='#_footnote_" + n +
\r
701 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
707 install: function(toclevels) {
\r
710 function reinstall() {
\r
711 asciidoc.footnotes();
\r
713 asciidoc.toc(toclevels);
\r
717 function reinstallAndRemoveTimer() {
\r
718 clearInterval(timerId);
\r
722 timerId = setInterval(reinstall, 500);
\r
723 if (document.addEventListener)
\r
724 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
\r
726 window.onload = reinstallAndRemoveTimer;
\r
730 asciidoc.install();
\r
734 <body class="article">
\r
736 <h1>ZSH-LOVERS(1)</h1>
\r
739 <div class="sect1">
\r
740 <h2 id="_name">NAME</h2>
\r
741 <div class="sectionbody">
\r
742 <div class="paragraph"><p>zsh-lovers - tips, tricks and examples for the Z shell</p></div>
\r
745 <div class="sect1">
\r
746 <h2 id="_synopsis">SYNOPSIS</h2>
\r
747 <div class="sectionbody">
\r
748 <div class="paragraph"><p>Just read it. ;-)</p></div>
\r
751 <div class="sect1">
\r
752 <h2 id="_overview">OVERVIEW</h2>
\r
753 <div class="sectionbody">
\r
754 <div class="paragraph"><p>Whenever we look at the zsh manual we wonder why there are no examples or those
\r
755 simply things in (shell) life. The zsh contains many features, but there was no
\r
756 manpage with some examples (like procmailex(5)). That’s why we wrote this
\r
758 <div class="paragraph"><p>Most of the tricks and oneliner come from the mailinglists zsh-users,
\r
759 zsh-workers, google, newsgroups and from ourself. See section <strong>LINKS</strong> for
\r
761 <div class="paragraph"><p>Note: This manpage (zsh-lovers(1)) is <strong>not</strong> an offical part of the Z shell! It’s
\r
762 just a just for fun - manpage ;)<br />
\r
763 For comments, bugreports and feedback take a quick look at the section <strong>BUGS</strong>.</p></div>
\r
766 <div class="sect1">
\r
767 <h2 id="_shell_scripting">SHELL-SCRIPTING</h2>
\r
768 <div class="sectionbody">
\r
769 <div class="paragraph"><p>This section provides some examples for often needed shellscript-stuff. Notice
\r
770 that you should not use otherwise most examples won’t work.<br />
\r
771 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski
\r
772 (<a href="http://www.chodorowski.com/projects/zws/">http://www.chodorowski.com/projects/zws/</a>):</p></div>
\r
773 <div class="listingblock">
\r
774 <div class="content">
\r
775 <pre><code>parse_options()
\r
781 zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help
\r
782 if [[ $? != 0 || "$o_help" != "" ]]; then
\r
783 echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"
\r
791 if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi
\r
793 # now use the function:
\r
794 parse_options $*</code></pre>
\r
798 <div class="sect1">
\r
799 <h2 id="_examples">EXAMPLES</h2>
\r
800 <div class="sectionbody">
\r
801 <div class="paragraph"><p>Available subsections are <strong>Aliases</strong>, <strong>Completion</strong>, <strong>Unsorted/Misc examples</strong>,
\r
802 <strong>(Recursive) Globbing - Examples</strong>, <strong>Modifiers usage</strong>, <strong>Redirection-Examples</strong>,
\r
803 <strong>ZMV-Examples</strong> and <strong>Module-Examples</strong>.</p></div>
\r
804 <div class="sect2">
\r
805 <h3 id="_aliases">ALIASES</h3>
\r
806 <div class="paragraph"><p>Suffix aliases are supported in zsh since version 4.2.0. Some examples:</p></div>
\r
807 <div class="listingblock">
\r
808 <div class="content">
\r
809 <pre><code>alias -s tex=vim
\r
811 alias -s org=w3m</code></pre>
\r
813 <div class="paragraph"><p>Now pressing return-key after entering <em>foobar.tex</em> starts vim with
\r
814 foobar.tex. Calling a html-file runs browser w3m. <em>www.zsh.org</em> and pressing
\r
815 enter starts w3m with argument www.zsh.org.<br />
\r
816 Global aliases can be used anywhere in the command line. Example:</p></div>
\r
817 <div class="listingblock">
\r
818 <div class="content">
\r
819 <pre><code>$ alias -g C='| wc -l'
\r
820 $ grep alias ~/.zsh/* C
\r
823 <div class="paragraph"><p>Some more or less useful global aliases (choose whether they are useful or not
\r
824 for you on your own):</p></div>
\r
825 <div class="listingblock">
\r
826 <div class="content">
\r
827 <pre><code>alias -g ...='../..'
\r
828 alias -g ....='../../..'
\r
829 alias -g .....='../../../..'
\r
830 alias -g CA="2>&1 | cat -A"
\r
831 alias -g C='| wc -l'
\r
832 alias -g D="DISPLAY=:0.0"
\r
833 alias -g DN=/dev/null
\r
834 alias -g ED="export DISPLAY=:0.0"
\r
835 alias -g EG='|& egrep'
\r
836 alias -g EH='|& head'
\r
837 alias -g EL='|& less'
\r
838 alias -g ELS='|& less -S'
\r
839 alias -g ETL='|& tail -20'
\r
840 alias -g ET='|& tail'
\r
841 alias -g F=' | fmt -'
\r
842 alias -g G='| egrep'
\r
843 alias -g H='| head'
\r
844 alias -g HL='|& head -20'
\r
845 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"
\r
846 alias -g LL="2>&1 | less"
\r
847 alias -g L="| less"
\r
848 alias -g LS='| less -S'
\r
849 alias -g MM='| most'
\r
850 alias -g M='| more'
\r
851 alias -g NE="2> /dev/null"
\r
852 alias -g NS='| sort -n'
\r
853 alias -g NUL="> /dev/null 2>&1"
\r
855 alias -g R=' > /c/aaa/tee.txt '
\r
856 alias -g RNS='| sort -nr'
\r
857 alias -g S='| sort'
\r
858 alias -g TL='| tail -20'
\r
859 alias -g T='| tail'
\r
860 alias -g US='| sort -u'
\r
861 alias -g VM=/var/log/messages
\r
862 alias -g X0G='| xargs -0 egrep'
\r
863 alias -g X0='| xargs -0'
\r
864 alias -g XG='| xargs egrep'
\r
865 alias -g X='| xargs'</code></pre>
\r
868 <div class="sect2">
\r
869 <h3 id="_completion">COMPLETION</h3>
\r
870 <div class="paragraph"><p>See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old
\r
871 style of zsh programmable completion, zshcompsys is the new completion
\r
872 system, zshcompwid are the zsh completion widgets.</p></div>
\r
873 <div class="paragraph"><p>Some functions, like _apt and _dpkg, are very slow. You can use a cache
\r
874 in order to proxy the list of results (like the list of available
\r
875 debian packages) Use a cache:</p></div>
\r
876 <div class="listingblock">
\r
877 <div class="content">
\r
878 <pre><code>zstyle ':completion:*' use-cache on
\r
879 zstyle ':completion:*' cache-path ~/.zsh/cache</code></pre>
\r
881 <div class="paragraph"><p>Prevent CVS files/directories from being completed:</p></div>
\r
882 <div class="listingblock">
\r
883 <div class="content">
\r
884 <pre><code>zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
\r
885 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'</code></pre>
\r
887 <div class="paragraph"><p>Fuzzy matching of completions for when you mistype them:</p></div>
\r
888 <div class="listingblock">
\r
889 <div class="content">
\r
890 <pre><code>zstyle ':completion:*' completer _complete _match _approximate
\r
891 zstyle ':completion:*:match:*' original only
\r
892 zstyle ':completion:*:approximate:*' max-errors 1 numeric</code></pre>
\r
894 <div class="paragraph"><p>And if you want the number of errors allowed by _approximate to
\r
895 increase with the length of what you have typed so far:</p></div>
\r
896 <div class="listingblock">
\r
897 <div class="content">
\r
898 <pre><code>zstyle -e ':completion:*:approximate:*' \
\r
899 max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'</code></pre>
\r
901 <div class="paragraph"><p>Ignore completion functions for commands you don’t have:</p></div>
\r
902 <div class="listingblock">
\r
903 <div class="content">
\r
904 <pre><code>zstyle ':completion:*:functions' ignored-patterns '_*'</code></pre>
\r
906 <div class="paragraph"><p>With helper functions like:</p></div>
\r
907 <div class="listingblock">
\r
908 <div class="content">
\r
909 <pre><code>xdvi() { command xdvi ${*:-*.dvi(om[1])} }</code></pre>
\r
911 <div class="paragraph"><p>you can avoid having to complete at all in many cases, but if you do,
\r
912 you might want to fall into menu selection immediately and to have the
\r
913 words sorted by time:</p></div>
\r
914 <div class="listingblock">
\r
915 <div class="content">
\r
916 <pre><code>zstyle ':completion:*:*:xdvi:*' menu yes select
\r
917 zstyle ':completion:*:*:xdvi:*' file-sort time</code></pre>
\r
919 <div class="paragraph"><p>Completing process IDs with menu selection:</p></div>
\r
920 <div class="listingblock">
\r
921 <div class="content">
\r
922 <pre><code>zstyle ':completion:*:*:kill:*' menu yes select
\r
923 zstyle ':completion:*:kill:*' force-list always</code></pre>
\r
925 <div class="paragraph"><p>If you end up using a directory as argument, this will remove the
\r
926 trailing slash (usefull in ln)</p></div>
\r
927 <div class="listingblock">
\r
928 <div class="content">
\r
929 <pre><code>zstyle ':completion:*' squeeze-slashes true</code></pre>
\r
931 <div class="paragraph"><p>cd will never select the parent directory (e.g.: cd ../<TAB>):</p></div>
\r
932 <div class="listingblock">
\r
933 <div class="content">
\r
934 <pre><code>zstyle ':completion:*:cd:*' ignore-parents parent pwd</code></pre>
\r
936 <div class="paragraph"><p>Another method for <em>quick change directories</em>. Add this to your ~/.zshrc, then just enter
\r
937 “cd …./dir”</p></div>
\r
938 <div class="listingblock">
\r
939 <div class="content">
\r
940 <pre><code>rationalise-dot() {
\r
941 if [[ $LBUFFER = *.. ]]; then
\r
947 zle -N rationalise-dot
\r
948 bindkey . rationalise-dot</code></pre>
\r
951 <div class="sect2">
\r
952 <h3 id="_unsorted_misc_examples">UNSORTED/MISC examples</h3>
\r
953 <div class="paragraph"><p>Hint: A list of valid glob Qualifiers can be found in zshexpn(1).
\r
954 See “man 1 zshexpn | less -p” Qualifiers for details.</p></div>
\r
955 <div class="listingblock">
\r
956 <div class="content">
\r
957 <pre><code># Get the names of all files that *don't* match a pattern *anywhere* on the
\r
958 # file (and without ``-L'' because its GNUish)
\r
959 $ print -rl -- *(.^e{'grep -q pattern $REPLY'})
\r
961 $ : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'})
\r
964 $ echo $[${RANDOM}%1000] # random between 0-999
\r
965 $ echo $[${RANDOM}%11+10] # random between 10-20
\r
966 $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)
\r
969 $ echo "${(j::)${(@Oa)${(s::):-hello}}}"
\r
971 # Show newest directory
\r
974 # random array element
\r
975 $ FILES=( .../files/* )
\r
976 $ feh $FILES[$RANDOM%$#FILES+1]
\r
978 # cat first line in all files in this dir
\r
979 $ for file (*(ND-.)) IFS= read -re < $file
\r
981 # test if a parameter is numeric
\r
982 $ if [[ $1 == <-> ]] ; then
\r
988 # Show me all the .c files for which there doesn't exist a .o file.
\r
989 $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)
\r
991 # All files in /var/ that are not owned by root
\r
992 $ ls -ld /var/*(^u:root)
\r
994 # All files for which the owner hat read and execute permissions
\r
997 # The same, but also others dont have execute permissions
\r
998 $ echo *(f:u+rx,o-x:)
\r
1000 # brace expansion - example
\r
1003 $ print -r -- $^X.$^Y
\r
1004 A.+ A.- B.+ B.- C.+ C.-
\r
1006 # Fetch the newest file containing the string 'fgractg*.log' in the
\r
1007 # filename and contains the string 'ORA-' in it
\r
1008 $ file=(fgractg*.log(Nm0om[1]))
\r
1009 $ (($#file)) && grep -l ORA- $file
\r
1011 $ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
\r
1012 > if [ -n "$files" ]; then
\r
1016 > file=$(ls -td $files | head -1)
\r
1017 > grep -l ORA- "$file"
\r
1020 # keep specified number of child processes running until entire task finished
\r
1021 $ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
\r
1023 # Remove zero length and .bak files in a directory
\r
1024 $ rm -i *(.L0) *.bak(.)
\r
1026 # print out files that dont have extensions
\r
1027 $ printf '%s\n' ^?*.*
\r
1028 $ printf '%s\n' ^?*.[^.]*(D)
\r
1029 $ ls -d -- ^?*.*(D)
\r
1031 # Finding files which does not contain a specific string
\r
1032 $ print -rl file* | comm -2 -3 - <(grep -l string file*)'
\r
1033 $ for f (file*(N)) grep -q string $f || print -r $f'
\r
1035 # Show/Check whether a option is set or not. It works both with $options as
\r
1037 $ echo $options[correct]
\r
1042 # Count the number of directories on the stack
\r
1043 $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
\r
1044 $ dirs -v | awk '{n=$1}END{print n+1}'
\r
1046 # Matching all files which do not have a dot in filename
\r
1049 # Show only the ip-address from ``ifconfig device''
\r
1050 # ifconfig from net-tools (Linux)
\r
1051 $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}
\r
1052 # ifconfig from 4.2BSD {Free,Net,Open}BSD
\r
1053 $ print ${$(/sbin/ifconfig tun0)[6]}
\r
1055 # Ping all the IP addresses in a couple of class C's or all hosts
\r
1057 $ for i in {1..254}; do ping -c 1 192.168.13.$i; done
\r
1060 $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done
\r
1062 $ for i in $(sed 's/#.*//' > /etc/hosts | awk '{print $2}')
\r
1064 : echo "Trying $i ... "
\r
1066 : echo '============================='
\r
1069 # load all available modules at startup
\r
1072 $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
\r
1075 # Rename all files within a directory such that their names get a numeral
\r
1076 # prefix in the default sort order.
\r
1077 $ i=1; for j in *; do mv $j $i.$j; ((i++)); done
\r
1078 $ i=1; for f in *; do mv $f $(echo $i | \
\r
1079 awk '{ printf("%03d", $0)}').$f; ((i++)); done
\r
1080 $ integer i=0; for f in *; do mv $f $[i+=1].$f; done
\r
1082 # Find (and print) all symbolic links without a target within the current
\r
1084 $ $ file **/*(D@) | fgrep broken
\r
1085 $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
\r
1086 $ echo **/*(@-^./=%p)
\r
1087 $ print -l **/*(-@)
\r
1089 # List all plain files that do not have extensions listed in `fignore'
\r
1090 $ ls **/*~*(${~${(j/|/)fignore}})(.)
\r
1091 # see above, but now omit executables
\r
1092 $ ls **/*~*(${~${(j/|/)fignore}})(.^*)
\r
1094 # Print out files that dont have extensions (require *setopt extendedglob*
\r
1095 # and *setopt dotglob*)
\r
1096 $ printf '%s\n' ^?*.*
\r
1098 # List files in reverse order sorted by name
\r
1099 $ print -rl -- *(On)
\r
1101 $ print -rl -- *(^on)
\r
1103 # Synonymic to ``ps ax | awk '{print $1}'''
\r
1104 $ print -l /proc/*/cwd(:h:t:s/self//)
\r
1106 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
\r
1110 > for i in /proc/<->/stat
\r
1112 > [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
\r
1116 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...
\r
1117 $ for (( i = 36#n; i <= 36#y; i++ )); do
\r
1118 > print ${$(([##36]i)):l}
\r
1120 # or in combination with ``dc''
\r
1121 $ print {$((##n))..$((##y))}P\ 10P | dc
\r
1122 # or with ``eval''
\r
1123 $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'
\r
1125 # foreach in one line of shell
\r
1126 $ for f (*) print -r -- $f
\r
1128 # copy a directory recursively without data/files
\r
1130 $ cd -- $dest_root
\r
1131 $ mkdir -p -- $dirs
\r
1133 $ find . -type d -exec env d="$dest_root" \
\r
1134 sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
\r
1136 # If `foo=23'', then print with 10 digit with leading '0'.
\r
1138 $ print ${(r:10::0:)foo}
\r
1140 # find the name of all the files in their home directory that have
\r
1141 # more than 20 characters in their file names
\r
1142 print -rl $HOME/${(l:20::?:)~:-}*
\r
1145 $ print -r -- ${(qq)m} > $nameoffile # save it
\r
1146 $ eval "m=($(cat -- $nameoffile)" # or use
\r
1147 $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
\r
1149 # get a "ls -l" on all the files in the tree that are younger than a
\r
1150 # specified age (e.g "ls -l" all the files in the tree that where
\r
1151 # modified in the last 2 days)
\r
1152 $ ls -tld **/*(m-2)
\r
1153 # This will give you a listing 1 file perl line (not à la ls -R).
\r
1154 # Think of an easy way to have a "ls -R" style output with
\r
1155 # only files newer than 2 day old.
\r
1156 $ for d (. ./**/*(/)) {
\r
1157 > print -r -- $'\n'${d}:
\r
1158 > cd $d && {
\r
1160 > (($#l)) && ls -ltd -- $l
\r
1164 # If you also want directories to be included even if their mtime
\r
1165 # is more than 2 days old:
\r
1166 $ for d (. ./**/*(/)) {
\r
1167 > print -r -- $'\n'${d}:
\r
1168 > cd $d && {
\r
1169 > l=(*(N/,m-2))
\r
1170 > (($#l)) && ls -ltd -- $l
\r
1174 # And if you want only the directories with mtime < 2 days to be listed:
\r
1175 $ for d (. ./**/*(N/m-2)) {
\r
1176 > print -r -- $'\n'${d}:
\r
1177 > cd $d && {
\r
1179 > (($#l)) && ls -ltd -- $l
\r
1185 $ echo ${(l:42::-:)}
\r
1186 # or use ``$COLUMS''
\r
1187 $ echo ${(l:$COLUMNS::-:)}
\r
1188 # and now with colors (require autoload colors ;colors)
\r
1189 $ echo "$bg[red]$fg[black]${(l:42::-:)}"
\r
1191 # Redirect STDERR to a command like xless without redirecting STDOUT as well.
\r
1192 $ foo 2>>(xless)
\r
1193 # but this executes the command asynchronously. To do it synchronously:
\r
1194 $ { { foo 1>&3 } 2>&1 | xless } 3>&1
\r
1196 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3
\r
1197 $ for i in *.mp3; do
\r
1198 > mv $i ${${(C)i}:s/Mp3/mp3/}
\r
1201 # Match file names containing only digits and ending with .xml (require
\r
1202 # *setopt kshglob*)
\r
1203 $ ls -l [0-9]##.xml
\r
1204 $ ls -l <0->.xml
\r
1206 # Remove all "non txt" files
\r
1209 # Move 200 files from a directory into another
\r
1210 $ mv -- *([1,200]) /another/Dir
\r
1212 # Convert images (foo.gif => foo.png):
\r
1213 $ for i in **/*.gif; convert $i $i:r.png
\r
1215 # convert a collection of mp3 files to wave or cdr,
\r
1216 # e.g. file.wav -> file.mp3)
\r
1217 $ for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
\r
1219 # Download with LaTeX2HTML created Files (for example the ZSH-Guide):
\r
1220 $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
\r
1221 > lynx -source $f >${f:t}
\r
1224 # Move all files in dir1 and dir2 that have line counts greater than 10 to
\r
1225 # another directory say "/more10"
\r
1226 $ mv dir[12]/**/*.cr(-.e{'((`wc -l < $REPLY` > 10))'}) /more10
\r
1228 # Make with dpkg a master-list of everyfile that it has installed
\r
1229 $ diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort)
\r
1231 # Replace this fucking Escape-Sequences:
\r
1232 $ autoload colors ; colors
\r
1233 $ print "$bg[cyan]$fg[blue]You are a idiot" >> /dev/pts/3
\r
1235 # Get ASCII value of a character
\r
1236 $ char=N ; print $((#char))
\r
1238 # Filename "Erweiterung"
\r
1239 # Note: The (N) says to use the nullglob option for this particular
\r
1241 $ for i in *.o(N); do
\r
1245 # Rename files; i. e. FOO to foo and bar to BAR
\r
1246 $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'
\r
1247 $ for i in *(.); mv $i ${i:u} # `bar to `BAR'
\r
1249 # Show all suid-files in $PATH
\r
1250 $ ls -latg ${(s.:.)PATH} | grep '^...s'
\r
1251 # or more complex ;)
\r
1252 $ print -l ${^path}/*(Ns,S)
\r
1253 # or show only executables with a user given pattern
\r
1254 $ print -l ${^path}/*vim*(*N)
\r
1256 # gzip files when containing a certain string
\r
1257 $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}
\r
1259 # A small one-liner, that reads from stdin and prints to stdout the first
\r
1260 # unique line i. e. does not print lines that have been printed before
\r
1261 # (this is similar to the unique command, but unique can only handle
\r
1262 # adjacent lines).
\r
1263 $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}
\r
1265 # Lists every executable in PATH
\r
1266 $ print -l ${^path}/*(-*N)
\r
1268 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?
\r
1269 $ ls **/*.c~(*/)#SCCS/*
\r
1271 # List all `README' - files case-insensitive with max. one typo
\r
1272 $ ls **/*(#ia2)readme
\r
1274 # case insensitive checking for variables
\r
1275 $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then
\r
1276 > echo "Penguin on board."
\r
1278 > echo "Not a Linux."
\r
1279 > fi</code></pre>
\r
1282 <div class="sect2">
\r
1283 <h3 id="_recursive_globbing_examples">(Recursive) Globbing - Examples</h3>
\r
1284 <div class="paragraph"><p>A list of valid glob Qualifiers can be found in zshexpn(1). <strong>Note:</strong>
\r
1285 **/ is equivalent to (*/)#! For example:</p></div>
\r
1286 <div class="listingblock">
\r
1287 <div class="content">
\r
1288 <pre><code>$ print (*/)#zsh_us.ps
\r
1289 zsh-4.2.3/Doc/zsh_us.ps
\r
1290 $ print **/zsh_us.ps
\r
1291 zsh-4.2.3/Doc/zsh_us.ps</code></pre>
\r
1293 <div class="listingblock">
\r
1294 <div class="content">
\r
1295 <pre><code># Search for `README' in all Subdirectories
\r
1298 # find directories that contain both "index.php" and "index.html", or in
\r
1299 # general, directories that contain more than one file matching "index.*"
\r
1300 $ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
\r
1302 $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l >= 2 ))':)
\r
1304 # Find command to search for directory name instead of basename
\r
1305 $ print -rl /**/*~^*/path(|/*)
\r
1306 # or - without Zsh
\r
1307 $ find / | grep -e /path/ -e '/path$'
\r
1309 # Print he path of the directories holding the ten biggest C regular files
\r
1310 # in the current directory and subdirectories.
\r
1311 $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
\r
1313 # Find files with size == 0 and send a mail
\r
1314 $ files=(**/*(ND.L0m+0m-2))
\r
1315 > (( $#files > 0 )) && print -rl -- $files | \
\r
1316 mailx -s "empty files" foo@bar.tdl
\r
1319 $ chmod 700 **/(.) # Only files
\r
1320 $ chmod 700 **/(/) # Only directories
\r
1322 # print out all of the files in that directory in 2 columns
\r
1323 $ print -rC2 -- ${1:[...]}/*(D:t)
\r
1324 # ^- number ob columns
\r
1325 # or - if you feel concerned about special characters - use
\r
1326 $ list=(${1:[...]}/*(ND:t))
\r
1327 $ (($#list)) && print -rC2 -- ${(V)list}
\r
1329 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
\r
1330 # (recursive, include dotfiles) remove the setgid/setuid flag and print
\r
1332 $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))
\r
1333 # or with a small script
\r
1334 $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {
\r
1335 > print -r -- $file
\r
1336 > chmod -s $file && print -r fixed $file
\r
1338 # or use ``zargs'' (require autoload zargs) prevent the arg list too
\r
1340 $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
\r
1342 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
\r
1343 $ ls -l foo<23->
\r
1345 # get all files that begin with the date strings from June 4 through
\r
1347 $ ls -l 200406{04..10}*(N)
\r
1348 # or if they are of the form 200406XX (require ``setopt extended_glob''
\r
1349 $ ls -l 200306<4-10>.*
\r
1351 # remove spaces from filenames
\r
1352 $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
\r
1354 # Show only all *.c and *.h - Files
\r
1357 # Show only all *.c - files and ignore `foo.c'
\r
1360 # show data to *really* binary format
\r
1361 $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \
\r
1362 > {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' < binary
\r
1364 # Show only world-readable files
\r
1367 # List files in the current directory are not writable by the owner
\r
1368 $ print -l ~/*(ND.^w)
\r
1370 # find and delete the files which are older than a given parameter
\r
1371 # (seconds/minutes/hours)
\r
1372 # deletes all regular file in /Dir that are older than 3 hours
\r
1373 $ rm -f /Dir/**/*(.mh+3)
\r
1374 # deletes all symlinks in /Dir that are older than 3 minutes
\r
1375 $ rm -f /Dir/**/*(@mm+3)
\r
1376 # deletes all non dirs in /Dir that are older than 30 seconds
\r
1377 $ rm -f /Dir/**/*(ms+30^/)
\r
1378 # deletes all folders, sub-folders and files older than one hour
\r
1379 $ rm ./**/*(.Dmh+1,.DL0)
\r
1380 # deletes all files more than 6 hours old
\r
1381 $ rm -f **/*(mh+6)
\r
1382 # removes all files but the ten newer ones (delete all but last 10
\r
1383 # files in a directory)
\r
1384 $ rm ./*(Om[1,-11])
\r
1385 Note: If you get a arg list too long, you use the builtin rm. For
\r
1387 $ zmodload zsh/files ; rm -f **/*(mh+6)
\r
1388 or use the zargs function:
\r
1389 $ autoload zargs ; zargs **/*(mh+6) -- rm -f
\r
1391 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
\r
1392 # Matching find all files in all subdirectories, searching recursively,
\r
1393 # which have a given name, case insensitive, are at least 50 KB large,
\r
1394 # no more than a week old and owned by the root user, and allowing up
\r
1395 # to a single error in the spelling of the name. In fact, the required
\r
1396 # expression looks like this:
\r
1397 $ ls **/(#ia1)name(LK+50mw-1u0)
\r
1399 # Change the UID from 102 to 666
\r
1400 $ chown 666 **/*(u102)
\r
1402 # List all files which have not been updated since last 10 hours
\r
1403 $ print -rl -- *(Dmh+10^/)
\r
1405 # delete only the oldest file in a directory
\r
1406 $ rm ./*filename*(Om[1])
\r
1408 # Sort the output from `ls -l' by file size
\r
1411 # find most recent file in a directory
\r
1412 $ setopt dotglob ; print directory/**/*(om[1])
\r
1414 # Show only empty files which nor `group' or `world writable'
\r
1417 # Find - and list - the ten newest files in directories and subdirs.
\r
1419 $ print -rl -- **/*(Dom[1,10])
\r
1421 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'').
\r
1422 $ ls -fl *(DOL[1,5])
\r
1424 # Display the 5-10 last modified files.
\r
1425 $ print -rl -- /path/to/dir/**/*(D.om[5,10])
\r
1427 # Find all files without a valid owner.
\r
1428 $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
\r
1430 # Find all the empty directories in a tree.
\r
1431 $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
\r
1432 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
\r
1433 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all
\r
1434 # subdirectories with no entries.
\r
1437 # Remove empty directories afterwards.
\r
1438 $ rmdir ./**/*(/od) 2> /dev/null
\r
1440 # Show only files which are owned by group `users'.
\r
1441 $ ls -l *(G[users])</code></pre>
\r
1444 <div class="sect2">
\r
1445 <h3 id="_modifiers_usage">Modifiers usage</h3>
\r
1446 <div class="paragraph"><p>Modifiers are a powerful mechanism that let you modify the results
\r
1447 returned by parameter, filename and history expansion. See zshexpn(1)
\r
1448 for details.</p></div>
\r
1449 <div class="listingblock">
\r
1450 <div class="content">
\r
1451 <pre><code># NOTE: Zsh 4.3.4 needed!
\r
1453 # files modified today
\r
1454 $ print *(e:age today now:)
\r
1455 # files modified since 5 pm
\r
1456 $ print *(e-age 17:00 now-)
\r
1457 # ... since 5 o'clock yesterda
\r
1458 $ print *(e-age yesterday,17:00 now-)
\r
1459 # ... from last Christmas before today
\r
1460 $ print *(e-age 2006/12/25 today-)
\r
1461 # ... before yesterday
\r
1462 $ print *(e-age 1970/01/01 yesterday-)
\r
1463 # all files modified between the start of those dates
\r
1464 $ print *(e:age 2006/10/04 2006/10/09:)
\r
1465 # all files modified on that date
\r
1466 $ print *(e:age 2006/10/04:)
\r
1468 $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
\r
1470 # Remove a trailing pathname component, leaving the head. This works like
\r
1475 # Remove all leading pathname components, leaving the tail. This works
\r
1476 # like `basename'.
\r
1480 # Remove the suffix from each file (*.sh in this example)
\r
1481 $f:e is $f file extension
\r
1482 :h --> head (dirname)
\r
1483 :t --> tail (basename)
\r
1484 :r --> rest (extension removed)
\r
1485 $ for f (*.sh) mv $f $f:r
\r
1487 # Remove a filename extension of the form `.xxx', leaving the root name.
\r
1493 # Remove all but the extension.
\r
1500 # Print the new command but do not execute it. Only works with history
\r
1507 # Quote the substituted words, escaping further substitutions.
\r
1514 # Convert the words to all lowercase.
\r
1521 # Convert the words to all uppercase.
\r
1528 # convert 1st char of a word to uppercase
\r
1529 $ foo="one two three four"
\r
1530 $ print -r -- "${(C)foo}"
\r
1531 One Two Three Four</code></pre>
\r
1534 <div class="sect2">
\r
1535 <h3 id="_redirection_examples">Redirection-Examples</h3>
\r
1536 <div class="paragraph"><p>See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))</p></div>
\r
1537 <div class="listingblock">
\r
1538 <div class="content">
\r
1539 <pre><code># Append `exit 1' at the end of all *.sh - files
\r
1540 $ echo "exit 1" >> *.sh
\r
1542 # adding files to foobar.tar.gz
\r
1543 $ eval set =(gunzip < foobar.tar.gz) '
\r
1544 tar rf $1 additional.txt &&gzip < $1 > foobar.tar.gz'
\r
1546 # Redirect output to a file AND display on screen
\r
1547 $ foobar >&1 > file1 > file2 > ..
\r
1549 # pipe single output to multiple inputs
\r
1550 $ zcat foobar.Z >> (gzip -9 > file1.gz) \
\r
1551 >> (bzip2 -9 > file1.bz2) \
\r
1552 >> (acb --best > file1.acb)
\r
1554 # Append /etc/services at the end of file `foo' and `bar'
\r
1555 $ cat /etc/services >> foo >> bar
\r
1558 $ echo An error >&2 2>&1 | sed -e 's/A/I/'
\r
1560 # send standard output of one process to standard input of several processes
\r
1563 $ process1 > >(process1) > >(process2)
\r
1565 # initializing a variable and simultaneously keeping terminal output
\r
1567 $ { a=$(command >&1 >& 3 3 > &- 2>&1);} 3>&1
\r
1569 # redirect stderr two times
\r
1570 $ setopt multios ; program 2> file2 > file1 2>&1
\r
1572 # Duplicating stdout and stderr to a logfile
\r
1573 $ exec 3>&1 > logfile 2>&2 2>&1 >&3 3>&-
\r
1575 # redirect stderr (only) to a file and to orig. stderr:
\r
1576 $ command 2>&2 2>stderr
\r
1577 # redirect stderr and stdout to separate files and both to orig. stdout:
\r
1578 $ command 2>&1 1>&1 2>stderr 1>stdout
\r
1579 # redirect stderr and stdout to separate files and stdout to orig. stdout
\r
1580 # AND stderr to orig. stderr:
\r
1581 $ command 2>&2 1>&1 2>stderr 1>stdout
\r
1583 # More fun with STDERR ;)
\r
1584 $ ./my-script.sh 2> >(grep -v moron >error.log)|process-output >output.log
\r
1585 $ echo "Thats STDOUT" >>(sed 's/stdout/another example/' > foobar)</code></pre>
\r
1588 <div class="sect2">
\r
1589 <h3 id="_zmv_examples_require_autoload_zmv">ZMV-Examples (require autoload zmv)</h3>
\r
1590 <div class="paragraph"><p><strong>Note:</strong> <em>-n</em> means no execution (just print what would happen). At</p></div>
\r
1591 <div class="listingblock">
\r
1592 <div class="content">
\r
1593 <pre><code># Remove illegal characters in a fat32 file system. Illegal characters are
\r
1594 # / : ; * ? " < > |
\r
1595 # NOTE: ``-Q'' and (D) is to include hidden files.
\r
1596 $ unwanted='[:;*?\"<>|]'
\r
1597 $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
\r
1599 # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
\r
1600 $ zmv '(*)hell(*)' '${1}heaven${2}'
\r
1602 $ zmv '*' '$f:s/hell/heaven/'
\r
1604 # remove round bracket within filenames
\r
1605 # i. e. foo-(bar).avi -> foo-bar.avi
\r
1606 $ zmv '*' '${f//[()]/}'
\r
1608 # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
\r
1611 1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
\r
1612 $ c=1 zmv '*.foo' '$((c++)).foo'
\r
1614 1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
\r
1616 # Rename "file.with.many.dots.txt" by substituting dots (exept for the last
\r
1617 # one!) with a space
\r
1618 $ touch {1..20}-file.with.many.dots.txt
\r
1619 $ zmv '(*.*)(.*)' '${1//./ }$2'
\r
1621 # Remove the first 4 chars from a filename
\r
1622 $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
\r
1624 # Rename names of all files under the current Dir to lower case, but keep
\r
1626 $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
\r
1628 # replace all 4th character, which is "1", with "2" and so on
\r
1630 $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
\r
1632 # Remove the first 15 characters from a string
\r
1633 $ touch 111111111111111{a-z}
\r
1635 $ zmv '*' '$f[16,-1]'
\r
1637 # Replace spaces (any number of them) with a single dash in file names
\r
1639 $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
\r
1641 $ find . -depth -name '* *' -exec bash -c '
\r
1642 > shopt -s extglob
\r
1644 > dir=${file%/*}
\r
1645 > name=${file##*/}
\r
1646 > newname=${name//*([ -]) *([ -])/-}
\r
1647 > mv -i -- "$file" "$Dir/$newname"' {} {} \;
\r
1649 # Clean up file names and remove special characters
\r
1651 $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
\r
1653 # Add *.py to a bunch of python scripts in a directory (some of them end
\r
1654 # in *.py and give them all a proper extension
\r
1656 $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
\r
1658 # lowercase all extensions (i. e. *.JPG) incl. subfolders
\r
1660 $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
\r
1661 # Or - without Zsh
\r
1662 $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
\r
1666 > *) mv "$f" "${f%.*}.jpg" ;
\r
1670 # remove leading zeros from file extension
\r
1673 filename.001 filename.003 filename.005 filename.007 filename.009
\r
1674 filename.002 filename.004 filename.006 filename.008 filename.010
\r
1675 $ zmv '(filename.)0##(?*)' '$1$2'
\r
1677 filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
\r
1682 foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
\r
1683 $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
\r
1685 foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
\r
1687 # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
\r
1689 $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
\r
1691 # See above, but now only files with a filename >= 30 chars
\r
1693 $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
\r
1695 # Replace spaces in filenames with a underline
\r
1697 $ zmv '* *' '$f:gs/ /_'
\r
1699 # Change the suffix from *.sh to *.pl
\r
1701 $ zmv -W '*.sh' '*.pl'
\r
1703 # Add a "".txt" extension to all the files within ${HOME}
\r
1704 # ``-.'' is to only rename regular files or symlinks to regular files,
\r
1705 # ``D'' is to also rename hidden files (dotfiles))
\r
1707 $ zmv -Q '/home/**/*(D-.)' '$f.txt'
\r
1708 # Or to only rename files that don't have an extension:
\r
1709 $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
\r
1711 # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
\r
1713 $ chars='[][?=+<>;",*-]'
\r
1714 $ zmv '(**/)(*)' '$1${2//$~chars/%}'
\r
1716 # Removing single quote from filenames (recursively)
\r
1718 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1720 # When a new file arrives (named file.txt) rename all files in order to
\r
1721 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
\r
1722 # file119.txt and so on ending with file.txt becoming file1.txt
\r
1724 $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
\r
1726 # lowercase/uppercase all files/directories
\r
1728 $ zmv '(*)' '${(L)1}' # lowercase
\r
1729 $ zmv '(*)' '${(U)1}' # uppercase
\r
1731 # Remove the suffix *.c from all C-Files
\r
1733 $ zmv '(*).c' '$1'
\r
1735 # Uppercase only the first letter of all *.mp3 - files
\r
1737 $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
\r
1739 # Copy the target `README' in same directory as each `Makefile'
\r
1741 $ zmv -C '(**/)Makefile' '${1}README'
\r
1743 # Removing single quote from filenames (recursively)
\r
1745 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1747 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
\r
1749 $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
\r
1750 $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively</code></pre>
\r
1753 <div class="sect2">
\r
1754 <h3 id="_module_examples">Module-Examples</h3>
\r
1755 <div class="paragraph"><p>Please read zshmodules(1) first!</p></div>
\r
1756 <div class="sect3">
\r
1757 <h4 id="_zsh_pcre_require_zmodload_zsh_pcre">zsh/pcre (require zmodload zsh/pcre)</h4>
\r
1758 <div class="listingblock">
\r
1759 <div class="content">
\r
1760 <pre><code># Copy files of a certain period (date indicated in the filenames)
\r
1761 $ zmodload zsh/pcre
\r
1762 $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)
\r
1764 $ m() { [[ $1 -pcre-match pcre-regexp ]] }
\r
1765 $ ls -d -- *(+m)</code></pre>
\r
1768 <div class="sect3">
\r
1769 <h4 id="_zsh_clone_require_zmodload_zsh_clone">zsh/clone (require zmodload zsh/clone)</h4>
\r
1770 <div class="listingblock">
\r
1771 <div class="content">
\r
1772 <pre><code># Creates a forked instance of the current shell ($! is set to zero) and
\r
1773 # execute ``command'' on /dev/tty8 (for this example).
\r
1774 $ zmodload zsh/clone
\r
1775 $ clone /dev/tty8 && (($! == 0)) && exec command</code></pre>
\r
1778 <div class="sect3">
\r
1779 <h4 id="_zsh_datetime_require_zmodload_zsh_datetime">zsh/datetime (require zmodload zsh/datetime)</h4>
\r
1780 <div class="listingblock">
\r
1781 <div class="content">
\r
1782 <pre><code> $ zmodload zsh/datetime
\r
1783 $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'
\r
1784 $ export DATE=`datereplacement`
\r
1787 # strip date from filename
\r
1788 $ $ zmodload zsh/datetime
\r
1789 $ setopt extendedglob
\r
1790 $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat
\r
1791 $ strftime -s pattern \
\r
1792 '???_???_<0-%Y%m%d>_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))
\r
1793 $ print -rl -- $~pattern
\r
1794 aaa_bbb_20041212_c.dat
\r
1795 $ print -rl -- $pattern
\r
1796 ???_???_<0-20050815>_?.dat
\r
1798 # Search files size == 0, to be based on the file name containing a date
\r
1799 # rather than the "last modified" date of the file
\r
1800 $ zmodload -i zsh/datetime
\r
1801 $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
\r
1802 $ files=(**/$file(N.L0))
\r
1803 $ (( $#files > 0 )) && print -rl -- $files | \
\r
1804 mailx -s "empty files" foo@bar.tdl</code></pre>
\r
1807 <div class="sect3">
\r
1808 <h4 id="_zsh_stat_require_zmodload_zsh_stat">zsh/stat (require zmodload zsh/stat)</h4>
\r
1809 <div class="listingblock">
\r
1810 <div class="content">
\r
1811 <pre><code># test if a symbolic link links to a certain file
\r
1812 $ zmodload -i zsh/stat
\r
1813 $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln
\r
1815 # comparing file dates
\r
1816 $ zmodload zsh/stat
\r
1819 $ touch bar & sleep 5 & touch foo
\r
1820 $ echo $file1 is $(($(stat +mtime $file2) - \
\r
1821 $(stat +mtime $file1))) seconds older than $file2.
\r
1822 bar is 5 seconds older than foo
\r
1824 # list the files of a disk smaller than some other file
\r
1825 $ zmodload zsh/stat
\r
1826 $ stat -A max +size some-other-file
\r
1827 $ print -rl ./**/*(D.L-$max)
\r
1829 # List the top 100 biggest files in a disk
\r
1830 $ zmodload zsh/stat
\r
1831 $ ls -fld ./**/*(d`stat +device .`OL[1,100])
\r
1833 # Get only the user name and the file names from (like
\r
1834 # ls -l * | awk '{print $3" " $8}')
\r
1835 $ zmodload zsh/stat
\r
1837 > stat -sA user +uid -- "$file" &&
\r
1838 > print -r -- "$user" "$file"
\r
1841 # get the difference between actual bytes of file and allocated bytes of file
\r
1842 $ zmodload zsh/stat
\r
1843 $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))
\r
1845 # Find largest file
\r
1846 # ``D'' : to include dot files (d lowercase is for device)
\r
1847 # ``O'' : reverse Ordered (o lowercase for non-reverse order)
\r
1848 # ``L'' : by file Length (l is for number of links)
\r
1849 # ``[1]'': return only first one
\r
1850 $ zmodload zsh/stat
\r
1851 $ stat +size ./*(DOL[1])
\r
1853 # file size in bytes
\r
1854 $ zmodload zsh/stat
\r
1855 $ stat -L +size ~/.zshrc
\r
1858 # Delete files in a directory that hasn't been accessed in the last ten days
\r
1859 # and send ONE mail to the owner of the files informing him/her of the files'
\r
1861 $ zmodload zsh/stat zsh/files
\r
1862 $ typeset -A f; f=()
\r
1863 $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
\r
1864 $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
\r
1866 # Get a "ls -l" on all the files in the tree that are younger than a
\r
1868 $ zmodload zsh/stat
\r
1869 $ for d (. ./**/*(N/m-2))
\r
1870 > print -r -- $'\n'$d: && cd $d && {
\r
1871 > for f (*(Nm-2om))
\r
1872 > stat -F '%b %d %H:%M' -LsAs -- $f &&
\r
1873 > print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \
\r
1874 > ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]}
\r
1878 # get file creation date
\r
1879 $ zmodload zsh/stat
\r
1880 $ stat -F '%d %m %Y' +mtime ~/.zshrc
\r
1882 $ stat -F '%D' +mtime ~/.zshrc
\r
1883 06/30/04</code></pre>
\r
1886 <div class="sect3">
\r
1887 <h4 id="_zsh_files_require_zmodload_zsh_files">zsh/files (require zmodload zsh/files)</h4>
\r
1888 <div class="listingblock">
\r
1889 <div class="content">
\r
1890 <pre><code># search a directory for files containing a certain string then copy those
\r
1891 # files to another directory.
\r
1892 $ zmodload zsh/files
\r
1894 $ cp $(grep -lZr foobar .) otherdirectory</code></pre>
\r
1897 <div class="sect3">
\r
1898 <h4 id="_zsh_mapfile_require_zmodload_zsh_mapfile">zsh/mapfile (require zmodload zsh/mapfile)</h4>
\r
1899 <div class="listingblock">
\r
1900 <div class="content">
\r
1901 <pre><code># grepping for two patterns
\r
1902 $ zmodload zsh/mapfile
\r
1904 $ pattern2="bar foo"
\r
1905 $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] && [[ $z = *$pattern1* && \
\r
1906 $z = *$pattern2* ]]'})
\r
1907 # or a solution in combination with zsh/pcre
\r
1908 $ zmodload -i zsh/mapfile zsh/pcre
\r
1910 $ pattern2="bar foo"
\r
1911 $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"
\r
1913 $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})
\r
1915 # equivalent for ``less /etc/passwd | grep -v root''
\r
1916 $ zmodload zsh/mapfile
\r
1918 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}
\r
1919 # or - for case insensitive
\r
1920 $ setopt extendedglob
\r
1921 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
\r
1923 # If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
\r
1924 # this empty tags (ones ending in '/>') so if encountered in the same
\r
1925 # order, the preceeding tags would become ``<TAGA/>1</TAGA>'' and
\r
1926 # ``<TAGB/>2</TAGB>''
\r
1927 $ zmodload zsh/mapfile
\r
1929 $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\
\r
1930 > (#im)<TAGA>*<\/TAGA>/<TAGA>$((++cnt))<\/TAGA>}
\r
1932 # removing all files in users Maildir/new that contain ``filename="gone.src''
\r
1933 $ zmodload zsh/{files,mapfile}
\r
1934 $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \
\r
1935 *filename=\"gone.scr\"* ]]'})
\r
1937 # Grep out the Title from a postscript file and append that value to the
\r
1938 # end of the filename
\r
1940 $ zmodload zsh/mapfile
\r
1941 $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'</code></pre>
\r
1944 <div class="sect3">
\r
1945 <h4 id="_zsh_mathfunc_require_zmodload_zsh_mathfunc">zsh/mathfunc (require zmodload zsh/mathfunc)</h4>
\r
1946 <div class="listingblock">
\r
1947 <div class="content">
\r
1948 <pre><code>$ zmodload zsh/mathfunc
\r
1949 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
\r
1950 -1.1102230246251565e-16
\r
1951 $ echo $(( pi = 4.0 * atan(1.0) ))
\r
1952 3.1415926535897931
\r
1953 $ echo $(( f = sin(0.3) ))
\r
1954 0.29552020666133955
\r
1955 $ print $((1e12 * rand48()))
\r
1956 847909677310.23413
\r
1957 $ print $(( rand48(seed) ))
\r
1958 0.01043488334700271</code></pre>
\r
1961 <div class="sect3">
\r
1962 <h4 id="_zsh_termcap_require_zmodload_zsh_termcap">zsh/termcap (require zmodload zsh/termcap)</h4>
\r
1963 <div class="listingblock">
\r
1964 <div class="content">
\r
1965 <pre><code> $ zmodload -ab zsh/termcap echotc
\r
1966 $ GREEN=`echotc AF 2`
\r
1967 $ YELLOW=`echotc AF 3`
\r
1968 $ RED=`echotc AF 1`
\r
1969 $ BRIGHTRED=`echotc md ; echotc AF 1`
\r
1970 $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred</code></pre>
\r
1973 <div class="sect3">
\r
1974 <h4 id="_zsh_zpty_require_zmodload_zsh_zpty">zsh/zpty (require zmodload zsh/zpty)</h4>
\r
1975 <div class="listingblock">
\r
1976 <div class="content">
\r
1977 <pre><code> $ zmodload zsh/zpty
\r
1978 $ zpty PW passwd $1
\r
1979 $ zpty PW passwd $1
\r
1980 # ``-r'': read the output of the command name.
\r
1981 # ``z'' : Parameter
\r
1982 $ zpty -r PW z '*password:'
\r
1983 # send the to command name the given strings as input
\r
1985 $ zpty -r PW z '*password:'
\r
1987 # The second form, with the -d option, is used to delete commands
\r
1988 # previously started, by supplying a list of their names. If no names
\r
1989 # are given, all commands are deleted. Deleting a command causes the HUP
\r
1990 # signal to be sent to the corresponding process.
\r
1991 $ zpty -d PW</code></pre>
\r
1994 <div class="sect3">
\r
1995 <h4 id="_zsh_net_socket_require_zmodload_zsh_net_socket">zsh/net/socket (require zmodload zsh/net/socket)</h4>
\r
1996 <div class="listingblock">
\r
1997 <div class="content">
\r
1998 <pre><code># ``-l'': open a socket listening on filename
\r
1999 # ``-d'': argument will be taken as the target file descriptor for the
\r
2001 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''
\r
2002 # (3.7.2: File descriptors)
\r
2003 $ zmodload zsh/net/socket
\r
2005 # ``-a'': accept an incoming connection to the socket
\r
2006 $ zsocket -a -d 4 3
\r
2007 $ zsocket -a -d 5 3 # accept a connection
\r
2008 $ echo foobar >&4
\r
2009 $ echo barfoo >&5
\r
2010 $ 4>&- 5>&- 3>&</code></pre>
\r
2013 <div class="sect3">
\r
2014 <h4 id="_zsh_zftp_require_zmodload_zsh_zftp">zsh/zftp (require zmodload zsh/zftp)</h4>
\r
2015 <div class="listingblock">
\r
2016 <div class="content">
\r
2017 <pre><code> $ autoload -U zfinit
\r
2019 $ zfparams www.example.invalid myuserid mypassword
\r
2022 $ zfls -l zshtips.html
\r
2023 $ zfput zshtips.html
\r
2024 $ zfls -l zshtips.html
\r
2026 # Automatically transfer files using FTP with error checking
\r
2027 $ autoload -U zfinit ; zfinit
\r
2028 $ zftp open host.name.invalid user passwd || exit
\r
2029 $ zftp get /remote/file > /local/file; r=$?
\r
2030 $ zftp close && exit r
\r
2032 # compress and ftp on the fly
\r
2033 $ autoload -U zfinit ; zfinit
\r
2034 $ zftp open host.name.invalid user password
\r
2035 $ zftp get $file | bzip2 > ${file}.bz2
\r
2038 # Recursice ``get''
\r
2039 $ autoload -U zfinit ; zfinit
\r
2041 $ zfcd daemontools
\r
2042 $ for file in `zfls` ; do
\r
2047 # Upload all regular files in $HOME/foobar (recursive) that are newer than
\r
2048 # two hours to ftp.foobar.invalid/path/to/upload
\r
2049 $ autoload -U zfinit ; zfinit
\r
2050 $ zfopen ftp.foobar.invalid/path/to/upload
\r
2052 $ zfput -r **/*(.mh-2)
\r
2055 # long list of files on a ftp
\r
2056 $ autoload -U zfinit ; zfinit
\r
2057 $ zfopen some-host
\r
2058 $ zfcd /some/remote/Dir
\r
2059 $ cd /some/local/Dir
\r
2060 # If the list.txt is located on the remote host, change to
\r
2061 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}
\r
2062 $ zfget ${(f)"$(cat list.txt)"}
\r
2063 $ zfclose</code></pre>
\r
2066 <div class="sect3">
\r
2067 <h4 id="_zsh_zselect_require_zmodload_zsh_zselect">zsh/zselect (require zmodload zsh/zselect)</h4>
\r
2068 <div class="listingblock">
\r
2069 <div class="content">
\r
2070 <pre><code># It's similar to
\r
2073 | $ stty -icanon min 0 time 50
\r
2076 | $ case "$yesno" in
\r
2077 | > yes) command1;;
\r
2078 | > *) command2;;
\r
2081 $ zmodload zsh/zselect
\r
2082 $ if zselect -t 500 -r 0 && read yesno && [ yes = "$yesno" ]; then
\r
2086 > fi</code></pre>
\r
2092 <div class="sect1">
\r
2093 <h2 id="_options">OPTIONS</h2>
\r
2094 <div class="sectionbody">
\r
2095 <div class="sect2">
\r
2096 <h3 id="_navigation_options">Navigation options</h3>
\r
2097 <div class="paragraph"><p><strong>auto_cd</strong> (allow one to change to a directory by entering it as a
\r
2098 command). <strong>auto_pushd</strong> (automatically append dirs to the push/pop list)
\r
2099 pushd_ignore_dups (and don’t duplicate them).</p></div>
\r
2101 <div class="sect2">
\r
2102 <h3 id="_misc">Misc</h3>
\r
2103 <div class="paragraph"><p><strong>no_hup</strong> (don’t send HUP signal to background jobs when exiting ZSH).
\r
2104 <strong>print_exit_value</strong> (show a message with the exit code when a command
\r
2105 returns with a non-zero exit code)</p></div>
\r
2106 <div class="sect3">
\r
2107 <h4 id="_history_options">History options</h4>
\r
2108 <div class="paragraph"><p><strong>hist_verify</strong> (let the user edit the command line after history
\r
2109 expansion (e.g. !ls) instead of immediately running it)<br />
\r
2110 Use the same history file for all sessions :<br />
\r
2111 <strong>setopt SHARE_HISTORY</strong></p></div>
\r
2113 <div class="sect3">
\r
2114 <h4 id="_privacy_security">Privacy / Security</h4>
\r
2115 <div class="paragraph"><p><strong>no_clobber</strong> (or set -C; prevent <em>></em> redirection from truncating
\r
2116 the given file if it already exists)</p></div>
\r
2118 <div class="sect3">
\r
2119 <h4 id="_spelling_correction">Spelling correction</h4>
\r
2120 <div class="paragraph"><p><strong>correct</strong> (automatically correct the spelling of commands).
\r
2121 <strong>correct_all</strong> (automatically correct the spelling of each word on the
\r
2122 command line) <strong>dvorak</strong> (dvorak layout)</p></div>
\r
2127 <div class="sect1">
\r
2128 <h2 id="_unsorted_misc">UNSORTED/MISC</h2>
\r
2129 <div class="sectionbody">
\r
2130 <div class="paragraph"><p>Mailpath: simple multiple mailpath:</p></div>
\r
2131 <div class="listingblock">
\r
2132 <div class="content">
\r
2133 <pre><code>mailpath=($HOME/Mail/mbox'?new mail in mbox'
\r
2134 $HOME/Mail/tux.u-strasbg'?new mail in tux'
\r
2135 $HOME/Mail/lilo'?new mail in lilo'
\r
2136 $HOME/Mail/ldap-fr'?new mail in ldap-fr')</code></pre>
\r
2138 <div class="paragraph"><p>Mailpath: dynamic mailpath:</p></div>
\r
2139 <div class="listingblock">
\r
2140 <div class="content">
\r
2141 <pre><code>typeset -a mailpath
\r
2142 for i in ~/Mail/Lists/*(.); do
\r
2143 mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."
\r
2146 <div class="paragraph"><p>Avoid globbing on special commands:</p></div>
\r
2147 <div class="listingblock">
\r
2148 <div class="content">
\r
2149 <pre><code>for com in alias expr find mattrib mcopy mdir mdel which;
\r
2150 alias $com="noglob $com"</code></pre>
\r
2152 <div class="paragraph"><p>For migrating your bashprompt to zsh use the script bash2zshprompt located in
\r
2153 the zsh source distribution under <em>Misc</em>.</p></div>
\r
2154 <div class="paragraph"><p>For migration from (t)csh to zsh use the c2z tool that converts csh
\r
2155 aliases and environment and shell variables to zsh. It does this by running
\r
2156 csh, and having csh report on aliases and variables. The script then converts
\r
2157 these to zsh startup files. It has some issues and usage information that are
\r
2158 documented at the top of this script.</p></div>
\r
2159 <div class="paragraph"><p>Here are functions to set the title and hardstatus of an <strong>XTerm</strong> or of <strong>GNU
\r
2160 Screen</strong> to <em>zsh</em> and the current directory, respectively, when the prompt is
\r
2161 displayed, and to the command name and rest of the command line, respectively,
\r
2162 when a command is executed:</p></div>
\r
2163 <div class="listingblock">
\r
2164 <div class="content">
\r
2165 <pre><code>function title {
\r
2166 if [[ $TERM == "screen" ]]; then
\r
2167 # Use these two for GNU Screen:
\r
2168 print -nR $' 33k'$1$' 33'\
\r
2169 print -nR $' 33]0;'$2$''
\r
2170 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
\r
2171 # Use this one instead for XTerms:
\r
2172 print -nR $' 33]0;'$*$''
\r
2175 function precmd { title zsh "$PWD" }
\r
2176 function preexec {
\r
2178 local -a cmd; cmd=(${(z)1})
\r
2179 title $cmd[1]:t "$cmd[2,-1]"
\r
2182 <div class="paragraph"><p>Put the following line into your ~/.screenrc to see this fancy hardstatus:</p></div>
\r
2183 <div class="listingblock">
\r
2184 <div class="content">
\r
2185 <pre><code>caption always "%3n %t%? (%u)%?%?: %h%?"</code></pre>
\r
2187 <div class="paragraph"><p>Special variables which are assigned:</p></div>
\r
2188 <div class="listingblock">
\r
2189 <div class="content">
\r
2190 <pre><code>$LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID
\r
2191 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath</code></pre>
\r
2195 <div class="sect1">
\r
2196 <h2 id="_links">LINKS</h2>
\r
2197 <div class="sectionbody">
\r
2198 <div class="dlist"><dl>
\r
2199 <dt class="hdlist1">
\r
2204 <strong><a href="http://www.zsh.org/">http://www.zsh.org/</a></strong>
\r
2207 <dt class="hdlist1">
\r
2212 <strong><a href="http://sourceforge.net/projects/zsh/">http://sourceforge.net/projects/zsh/</a></strong>
\r
2215 <dt class="hdlist1">
\r
2216 Z shell page at sunsite.dk
\r
2220 <strong><a href="http://zsh.sunsite.dk/">http://zsh.sunsite.dk/</a></strong>
\r
2223 <dt class="hdlist1">
\r
2224 From Bash to Z Shell: Conquering the Command Line - the book
\r
2228 <strong><a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a></strong>
\r
2231 <dt class="hdlist1">
\r
2232 "Zsh - die magische Shell" (german book about Zsh) by Sven Guckes and Julius Plenz
\r
2236 <strong><a href="http://zshbuch.org/">http://zshbuch.org/</a></strong>
\r
2239 <dt class="hdlist1">
\r
2240 Mailinglistarchive
\r
2244 <strong><a href="http://www.zsh.org/mla/">http://www.zsh.org/mla/</a></strong>
\r
2247 <dt class="hdlist1">
\r
2252 <strong><a href="http://zsh.dotsrc.org/FAQ/">http://zsh.dotsrc.org/FAQ/</a></strong>
\r
2255 <dt class="hdlist1">
\r
2260 <strong><a href="http://zsh.sunsite.dk/Guide/">http://zsh.sunsite.dk/Guide/</a></strong>
\r
2263 <dt class="hdlist1">
\r
2268 <strong><a href="http://zshwiki.org/home/">http://zshwiki.org/home/</a></strong>
\r
2271 <dt class="hdlist1">
\r
2272 A short introduction from BYU
\r
2276 <strong><a href="http://docs.cs.byu.edu/linux/advanced/zsh.html">http://docs.cs.byu.edu/linux/advanced/zsh.html</a></strong>
\r
2279 <dt class="hdlist1">
\r
2284 <strong><a href="http://stchaz.free.fr/mouse.zsh">http://stchaz.free.fr/mouse.zsh</a></strong>
\r
2287 <dt class="hdlist1">
\r
2288 Curtains up: introducing the Z shell
\r
2292 <strong><a href="http://www-128.ibm.com/developerworks/linux/library/l-z.html?dwzone=linux">http://www-128.ibm.com/developerworks/linux/library/l-z.html?dwzone=linux</a></strong>
\r
2295 <dt class="hdlist1">
\r
2296 ZSH-Liebhaberseite (german)
\r
2300 <strong><a href="http://michael-prokop.at/computer/tools_zsh_liebhaber.html">http://michael-prokop.at/computer/tools_zsh_liebhaber.html</a></strong>
\r
2303 <dt class="hdlist1">
\r
2304 ZSH-Seite von Michael Prokop (german)
\r
2308 <strong><a href="http://michael-prokop.at/computer/tools_zsh.html">http://michael-prokop.at/computer/tools_zsh.html</a></strong>
\r
2311 <dt class="hdlist1">
\r
2312 ZSH Prompt introduction
\r
2316 <strong><a href="http://aperiodic.net/phil/prompt/">http://aperiodic.net/phil/prompt/</a></strong>
\r
2319 <dt class="hdlist1">
\r
2320 ft’s zsh configuration
\r
2324 <strong><a href="http://ft.bewatermyfriend.org/comp/zsh.html">http://ft.bewatermyfriend.org/comp/zsh.html</a></strong>
\r
2327 <dt class="hdlist1">
\r
2328 Adam’s ZSH page
\r
2332 <strong><a href="http://www.adamspiers.org/computing/zsh/">http://www.adamspiers.org/computing/zsh/</a></strong>
\r
2335 <dt class="hdlist1">
\r
2336 Zzappers Best of ZSH Tips
\r
2340 <strong><a href="http://www.rayninfo.co.uk/tips/zshtips.html">http://www.rayninfo.co.uk/tips/zshtips.html</a></strong>
\r
2343 <dt class="hdlist1">
\r
2344 Zsh Webpage by Christian Schneider
\r
2348 <strong><a href="http://www.strcat.de/zsh/">http://www.strcat.de/zsh/</a></strong>
\r
2351 <dt class="hdlist1">
\r
2352 The zsh-lovers webpage
\r
2356 <strong><a href="http://grml.org/zsh/">http://grml.org/zsh/</a></strong>
\r
2359 <dt class="hdlist1">
\r
2364 <strong>#zsh at irc.libera.chat</strong>
\r
2367 <dt class="hdlist1">
\r
2368 The Z shell reference-card (included in the zsh-lovers debian-package)
\r
2372 <strong><a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a></strong>
\r
2378 <div class="sect1">
\r
2379 <h2 id="_authors">AUTHORS</h2>
\r
2380 <div class="sectionbody">
\r
2381 <div class="paragraph"><p>This manpage was written by Michael Prokop, Christian <em>strcat</em>
\r
2382 Schneider and Matthias Kopfermann. But many ideas have been taken from
\r
2383 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),
\r
2384 google, newsgroups and the zsh-Wiki.<br />
\r
2385 Thanks for your cool and incredible tips. We learned much from you!</p></div>
\r
2386 <div class="paragraph"><p>In alphabetic order:</p></div>
\r
2387 <div class="listingblock">
\r
2388 <div class="content">
\r
2389 <pre><code>Andrew 'zefram' Main - http://www.fysh.org/~zefram/
\r
2390 Barton E. Schaefer - http://www.well.com/user/barts/
\r
2391 Matthias Kopfermann - http://www.infodrom.north.de/~matthi/
\r
2392 Oliver Kiddle - http://people.freenet.de/opk/
\r
2393 Paul Falstad - http://www.falstad.com/
\r
2394 Peter Stephenson - http://homepage.ntlworld.com/p.w.stephenson/
\r
2396 Stephane Chazelas - http://stephane.chazelas.free.fr/
\r
2397 Sven Guckes - http://www.guckes.net/
\r
2398 Sven Wischnowsky - http://w9y.de/zsh/zshrc</code></pre>
\r
2402 <div class="sect1">
\r
2403 <h2 id="_see_also">SEE ALSO</h2>
\r
2404 <div class="sectionbody">
\r
2405 <div class="paragraph"><p>Manpages of zsh:</p></div>
\r
2406 <div class="listingblock">
\r
2407 <div class="content">
\r
2408 <pre><code> zsh Zsh overview
\r
2409 zshall Tthe Z shell meta-man page
\r
2410 zshbuiltins Zsh built-in commands
\r
2411 zshcalsys zsh calendar system
\r
2412 zshcompctl zsh programmable completion
\r
2413 zshcompsys Zsh completion system
\r
2414 zshcompwid Zsh completion widgets
\r
2415 zshcontrib User contributions to zsh
\r
2416 zshexpn Zsh expansion and substitution
\r
2417 zshmisc Anything not fitting into the other sections
\r
2418 zshmodules Zsh loadable modules
\r
2419 zshoptions Zsh options
\r
2420 zshparam Zsh parameters
\r
2421 zshroadmap Informal introduction to the zsh manual
\r
2422 zshtcpsys Zsh tcp system
\r
2423 zshzle Zsh command line editing
\r
2424 zshzftpsys Zsh built-in FTP client
\r
2425 zshall Meta-man page containing all of the above</code></pre>
\r
2427 <div class="paragraph"><p>Note: especially <em>man zshcontrib</em> covers very useful topics!<br />
\r
2428 Book: <strong>From Bash to Z Shell</strong> by Oliver Kiddle, Jerry Peck and Peter
\r
2429 Stephenson. <strong>ISBN: 1590593766</strong>. - <strong><a href="http://www.bash2zsh.com/">bash2zsh.com</a></strong><br />
\r
2430 Also take a look at the section <strong>LINKS</strong> in this manpage.</p></div>
\r
2433 <div class="sect1">
\r
2434 <h2 id="_bugs">BUGS</h2>
\r
2435 <div class="sectionbody">
\r
2436 <div class="paragraph"><p>Probably. This manpage might be never complete. So please report bugs,
\r
2437 feedback and suggestions to <<a href="mailto:zsh-lovers@michael-prokop.at">zsh-lovers@michael-prokop.at</a>>. Thank
\r
2441 <div class="sect1">
\r
2442 <h2 id="_copyright">COPYRIGHT</h2>
\r
2443 <div class="sectionbody">
\r
2444 <div class="paragraph"><p>Copyright (C) Michael Prokop, Christian Schneider and Matthias
\r
2445 Kopfermann.</p></div>
\r
2449 <div id="footnotes"><hr /></div>
\r
2451 <div id="footer-text">
\r
2452 Last updated 2010-07-28 21:55:37 UTC
\r