1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
\r
3 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
\r
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
\r
6 <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
\r
7 <meta name="generator" content="AsciiDoc 10.2.0" />
\r
8 <title>ZSH-LOVERS(1)</title>
\r
9 <style type="text/css">
\r
10 /* Shared CSS for AsciiDoc xhtml11 and html5 backends */
\r
14 font-family: Georgia,serif;
\r
18 h1, h2, h3, h4, h5, h6,
\r
19 div.title, caption.title,
\r
20 thead, p.table.header,
\r
22 #author, #revnumber, #revdate, #revremark,
\r
24 font-family: Arial,Helvetica,sans-serif;
\r
28 margin: 1em 5% 1em 5%;
\r
33 text-decoration: underline;
\r
49 h1, h2, h3, h4, h5, h6 {
\r
52 margin-bottom: 0.5em;
\r
57 border-bottom: 2px solid silver;
\r
77 border: 1px solid silver;
\r
82 margin-bottom: 0.5em;
\r
88 ul > li { color: #aaa; }
\r
89 ul > li > * { color: black; }
\r
91 .monospaced, code, pre {
\r
92 font-family: "Courier New", Courier, monospace;
\r
99 white-space: pre-wrap;
\r
109 #revnumber, #revdate, #revremark {
\r
114 border-top: 2px solid silver;
\r
115 padding-top: 0.5em;
\r
120 padding-bottom: 0.5em;
\r
124 padding-bottom: 0.5em;
\r
129 margin-bottom: 1.5em;
\r
131 div.imageblock, div.exampleblock, div.verseblock,
\r
132 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
\r
133 div.admonitionblock {
\r
135 margin-bottom: 1.5em;
\r
137 div.admonitionblock {
\r
139 margin-bottom: 2.0em;
\r
144 div.content { /* Block element content. */
\r
148 /* Block element titles. */
\r
149 div.title, caption.title {
\r
154 margin-bottom: 0.5em;
\r
160 td div.title:first-child {
\r
163 div.content div.title:first-child {
\r
166 div.content + div.title {
\r
170 div.sidebarblock > div.content {
\r
171 background: #ffffee;
\r
172 border: 1px solid #dddddd;
\r
173 border-left: 4px solid #f0f0f0;
\r
177 div.listingblock > div.content {
\r
178 border: 1px solid #dddddd;
\r
179 border-left: 5px solid #f0f0f0;
\r
180 background: #f8f8f8;
\r
184 div.quoteblock, div.verseblock {
\r
185 padding-left: 1.0em;
\r
186 margin-left: 1.0em;
\r
188 border-left: 5px solid #f0f0f0;
\r
192 div.quoteblock > div.attribution {
\r
193 padding-top: 0.5em;
\r
197 div.verseblock > pre.content {
\r
198 font-family: inherit;
\r
199 font-size: inherit;
\r
201 div.verseblock > div.attribution {
\r
202 padding-top: 0.75em;
\r
205 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
\r
206 div.verseblock + div.attribution {
\r
210 div.admonitionblock .icon {
\r
211 vertical-align: top;
\r
214 text-decoration: underline;
\r
216 padding-right: 0.5em;
\r
218 div.admonitionblock td.content {
\r
219 padding-left: 0.5em;
\r
220 border-left: 3px solid #dddddd;
\r
223 div.exampleblock > div.content {
\r
224 border-left: 3px solid #dddddd;
\r
225 padding-left: 0.5em;
\r
228 div.imageblock div.content { padding-left: 0; }
\r
229 span.image img { border-style: none; vertical-align: text-bottom; }
\r
230 a.image:visited { color: white; }
\r
234 margin-bottom: 0.8em;
\r
239 font-style: normal;
\r
242 dd > *:first-child {
\r
247 list-style-position: outside;
\r
250 list-style-type: decimal;
\r
253 list-style-type: lower-alpha;
\r
256 list-style-type: upper-alpha;
\r
259 list-style-type: lower-roman;
\r
262 list-style-type: upper-roman;
\r
265 div.compact ul, div.compact ol,
\r
266 div.compact p, div.compact p,
\r
267 div.compact div, div.compact div {
\r
269 margin-bottom: 0.1em;
\r
281 margin-bottom: 0.8em;
\r
284 padding-bottom: 15px;
\r
286 dt.hdlist1.strong, td.hdlist1.strong {
\r
290 vertical-align: top;
\r
291 font-style: normal;
\r
292 padding-right: 0.8em;
\r
296 vertical-align: top;
\r
298 div.hdlist.compact tr {
\r
304 background: yellow;
\r
307 .footnote, .footnoteref {
\r
311 span.footnote, span.footnoteref {
\r
312 vertical-align: super;
\r
316 margin: 20px 0 20px 0;
\r
317 padding: 7px 0 0 0;
\r
320 #footnotes div.footnote {
\r
326 border-top: 1px solid silver;
\r
335 padding-right: 0.5em;
\r
336 padding-bottom: 0.3em;
\r
337 vertical-align: top;
\r
339 div.colist td img {
\r
344 #footer-badges { display: none; }
\r
348 margin-bottom: 2.5em;
\r
356 margin-bottom: 0.1em;
\r
359 div.toclevel0, div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
\r
376 span.aqua { color: aqua; }
\r
377 span.black { color: black; }
\r
378 span.blue { color: blue; }
\r
379 span.fuchsia { color: fuchsia; }
\r
380 span.gray { color: gray; }
\r
381 span.green { color: green; }
\r
382 span.lime { color: lime; }
\r
383 span.maroon { color: maroon; }
\r
384 span.navy { color: navy; }
\r
385 span.olive { color: olive; }
\r
386 span.purple { color: purple; }
\r
387 span.red { color: red; }
\r
388 span.silver { color: silver; }
\r
389 span.teal { color: teal; }
\r
390 span.white { color: white; }
\r
391 span.yellow { color: yellow; }
\r
393 span.aqua-background { background: aqua; }
\r
394 span.black-background { background: black; }
\r
395 span.blue-background { background: blue; }
\r
396 span.fuchsia-background { background: fuchsia; }
\r
397 span.gray-background { background: gray; }
\r
398 span.green-background { background: green; }
\r
399 span.lime-background { background: lime; }
\r
400 span.maroon-background { background: maroon; }
\r
401 span.navy-background { background: navy; }
\r
402 span.olive-background { background: olive; }
\r
403 span.purple-background { background: purple; }
\r
404 span.red-background { background: red; }
\r
405 span.silver-background { background: silver; }
\r
406 span.teal-background { background: teal; }
\r
407 span.white-background { background: white; }
\r
408 span.yellow-background { background: yellow; }
\r
410 span.big { font-size: 2em; }
\r
411 span.small { font-size: 0.6em; }
\r
413 span.underline { text-decoration: underline; }
\r
414 span.overline { text-decoration: overline; }
\r
415 span.line-through { text-decoration: line-through; }
\r
417 div.unbreakable { page-break-inside: avoid; }
\r
427 margin-bottom: 1.5em;
\r
429 div.tableblock > table {
\r
430 border: 3px solid #527bbd;
\r
432 thead, p.table.header {
\r
439 /* Because the table frame attribute is overridden by CSS in most browsers. */
\r
440 div.tableblock > table[frame="void"] {
\r
441 border-style: none;
\r
443 div.tableblock > table[frame="hsides"] {
\r
444 border-left-style: none;
\r
445 border-right-style: none;
\r
447 div.tableblock > table[frame="vsides"] {
\r
448 border-top-style: none;
\r
449 border-bottom-style: none;
\r
460 margin-bottom: 1.5em;
\r
462 thead, p.tableblock.header {
\r
471 border-spacing: 0px;
\r
472 border-style: solid;
\r
473 border-color: #527bbd;
\r
474 border-collapse: collapse;
\r
476 th.tableblock, td.tableblock {
\r
479 border-style: solid;
\r
480 border-color: #527bbd;
\r
483 table.tableblock.frame-topbot {
\r
484 border-left-style: hidden;
\r
485 border-right-style: hidden;
\r
487 table.tableblock.frame-sides {
\r
488 border-top-style: hidden;
\r
489 border-bottom-style: hidden;
\r
491 table.tableblock.frame-none {
\r
492 border-style: hidden;
\r
495 th.tableblock.halign-left, td.tableblock.halign-left {
\r
498 th.tableblock.halign-center, td.tableblock.halign-center {
\r
499 text-align: center;
\r
501 th.tableblock.halign-right, td.tableblock.halign-right {
\r
505 th.tableblock.valign-top, td.tableblock.valign-top {
\r
506 vertical-align: top;
\r
508 th.tableblock.valign-middle, td.tableblock.valign-middle {
\r
509 vertical-align: middle;
\r
511 th.tableblock.valign-bottom, td.tableblock.valign-bottom {
\r
512 vertical-align: bottom;
\r
522 padding-top: 0.5em;
\r
523 padding-bottom: 0.5em;
\r
524 border-top: 2px solid silver;
\r
525 border-bottom: 2px solid silver;
\r
528 border-style: none;
\r
530 body.manpage div.sectionbody {
\r
535 body.manpage div#toc { display: none; }
\r
540 <script type="text/javascript">
\r
542 var asciidoc = { // Namespace.
\r
544 /////////////////////////////////////////////////////////////////////
\r
545 // Table Of Contents generator
\r
546 /////////////////////////////////////////////////////////////////////
\r
548 /* Author: Mihai Bazon, September 2002
\r
549 * http://students.infoiasi.ro/~mishoo
\r
551 * Table Of Content generator
\r
554 * Feel free to use this script under the terms of the GNU General Public
\r
555 * License, as long as you do not remove or alter this notice.
\r
558 /* modified by Troy D. Hanson, September 2006. License: GPL */
\r
559 /* modified by Stuart Rackham, 2006, 2009. License: GPL */
\r
561 // toclevels = 1..4.
\r
562 toc: function (toclevels) {
\r
564 function getText(el) {
\r
566 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
567 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
\r
569 else if (i.firstChild != null)
\r
570 text += getText(i);
\r
575 function TocEntry(el, text, toclevel) {
\r
578 this.toclevel = toclevel;
\r
581 function tocEntries(el, toclevels) {
\r
582 var result = new Array;
\r
583 var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
\r
584 // Function that scans the DOM tree for header elements (the DOM2
\r
585 // nodeIterator API would be a better technique but not supported by all
\r
587 var iterate = function (el) {
\r
588 for (var i = el.firstChild; i != null; i = i.nextSibling) {
\r
589 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
\r
590 var mo = re.exec(i.tagName);
\r
591 if (mo && (i.getAttribute("class") || i.getAttribute("className")) != "float") {
\r
592 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
\r
602 var toc = document.getElementById("toc");
\r
607 // Delete existing TOC entries in case we're reloading the TOC.
\r
608 var tocEntriesToRemove = [];
\r
610 for (i = 0; i < toc.childNodes.length; i++) {
\r
611 var entry = toc.childNodes[i];
\r
612 if (entry.nodeName.toLowerCase() == 'div'
\r
613 && entry.getAttribute("class")
\r
614 && entry.getAttribute("class").match(/^toclevel/))
\r
615 tocEntriesToRemove.push(entry);
\r
617 for (i = 0; i < tocEntriesToRemove.length; i++) {
\r
618 toc.removeChild(tocEntriesToRemove[i]);
\r
621 // Rebuild TOC entries.
\r
622 var entries = tocEntries(document.getElementById("content"), toclevels);
\r
623 for (var i = 0; i < entries.length; ++i) {
\r
624 var entry = entries[i];
\r
625 if (entry.element.id == "")
\r
626 entry.element.id = "_toc_" + i;
\r
627 var a = document.createElement("a");
\r
628 a.href = "#" + entry.element.id;
\r
629 a.appendChild(document.createTextNode(entry.text));
\r
630 var div = document.createElement("div");
\r
631 div.appendChild(a);
\r
632 div.className = "toclevel" + entry.toclevel;
\r
633 toc.appendChild(div);
\r
635 if (entries.length == 0)
\r
636 toc.parentNode.removeChild(toc);
\r
640 /////////////////////////////////////////////////////////////////////
\r
641 // Footnotes generator
\r
642 /////////////////////////////////////////////////////////////////////
\r
644 /* Based on footnote generation code from:
\r
645 * http://www.brandspankingnew.net/archive/2005/07/format_footnote.html
\r
648 footnotes: function () {
\r
649 // Delete existing footnote entries in case we're reloading the footnodes.
\r
651 var noteholder = document.getElementById("footnotes");
\r
655 var entriesToRemove = [];
\r
656 for (i = 0; i < noteholder.childNodes.length; i++) {
\r
657 var entry = noteholder.childNodes[i];
\r
658 if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
\r
659 entriesToRemove.push(entry);
\r
661 for (i = 0; i < entriesToRemove.length; i++) {
\r
662 noteholder.removeChild(entriesToRemove[i]);
\r
665 // Rebuild footnote entries.
\r
666 var cont = document.getElementById("content");
\r
667 var spans = cont.getElementsByTagName("span");
\r
670 for (i=0; i<spans.length; i++) {
\r
671 if (spans[i].className == "footnote") {
\r
673 var note = spans[i].getAttribute("data-note");
\r
675 // Use [\s\S] in place of . so multi-line matches work.
\r
676 // Because JavaScript has no s (dotall) regex flag.
\r
677 note = spans[i].innerHTML.match(/\s*\[([\s\S]*)]\s*/)[1];
\r
678 spans[i].innerHTML =
\r
679 "[<a id='_footnoteref_" + n + "' href='#_footnote_" + n +
\r
680 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
681 spans[i].setAttribute("data-note", note);
\r
683 noteholder.innerHTML +=
\r
684 "<div class='footnote' id='_footnote_" + n + "'>" +
\r
685 "<a href='#_footnoteref_" + n + "' title='Return to text'>" +
\r
686 n + "</a>. " + note + "</div>";
\r
687 var id =spans[i].getAttribute("id");
\r
688 if (id != null) refs["#"+id] = n;
\r
692 noteholder.parentNode.removeChild(noteholder);
\r
694 // Process footnoterefs.
\r
695 for (i=0; i<spans.length; i++) {
\r
696 if (spans[i].className == "footnoteref") {
\r
697 var href = spans[i].getElementsByTagName("a")[0].getAttribute("href");
\r
698 href = href.match(/#.*/)[0]; // Because IE return full URL.
\r
700 spans[i].innerHTML =
\r
701 "[<a href='#_footnote_" + n +
\r
702 "' title='View footnote' class='footnote'>" + n + "</a>]";
\r
708 install: function(toclevels) {
\r
711 function reinstall() {
\r
712 asciidoc.footnotes();
\r
714 asciidoc.toc(toclevels);
\r
718 function reinstallAndRemoveTimer() {
\r
719 clearInterval(timerId);
\r
723 timerId = setInterval(reinstall, 500);
\r
724 if (document.addEventListener)
\r
725 document.addEventListener("DOMContentLoaded", reinstallAndRemoveTimer, false);
\r
727 window.onload = reinstallAndRemoveTimer;
\r
731 asciidoc.install();
\r
735 <body class="article">
\r
737 <h1>ZSH-LOVERS(1)</h1>
\r
740 <div class="sect1">
\r
741 <h2 id="_name">NAME</h2>
\r
742 <div class="sectionbody">
\r
743 <div class="paragraph"><p>zsh-lovers - tips, tricks and examples for the Z shell</p></div>
\r
746 <div class="sect1">
\r
747 <h2 id="_synopsis">SYNOPSIS</h2>
\r
748 <div class="sectionbody">
\r
749 <div class="paragraph"><p>Just read it. ;-)</p></div>
\r
752 <div class="sect1">
\r
753 <h2 id="_overview">OVERVIEW</h2>
\r
754 <div class="sectionbody">
\r
755 <div class="paragraph"><p>Whenever we look at the zsh manual we wonder why there are no examples or those
\r
756 simply things in (shell) life. The zsh contains many features, but there was no
\r
757 manpage with some examples (like procmailex(5)). That’s why we wrote this
\r
759 <div class="paragraph"><p>Most of the tricks and oneliner come from the mailinglists zsh-users,
\r
760 zsh-workers, google, newsgroups and from ourself. See section <strong>LINKS</strong> for
\r
762 <div class="paragraph"><p>Note: This manpage (zsh-lovers(1)) is <strong>not</strong> an official part of the Z shell! It’s
\r
763 just a just for fun - manpage ;)<br />
\r
764 For comments, bugreports and feedback take a quick look at the section <strong>BUGS</strong>.</p></div>
\r
767 <div class="sect1">
\r
768 <h2 id="_shell_scripting">SHELL-SCRIPTING</h2>
\r
769 <div class="sectionbody">
\r
770 <div class="paragraph"><p>This section provides some examples for often needed shellscript-stuff. Notice
\r
771 that you should not use otherwise most examples won’t work.<br />
\r
772 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski
\r
773 (<a href="http://www.chodorowski.com/projects/zws/">http://www.chodorowski.com/projects/zws/</a>):</p></div>
\r
774 <div class="listingblock">
\r
775 <div class="content">
\r
776 <pre><code>parse_options()
\r
782 zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help
\r
783 if [[ $? != 0 || "$o_help" != "" ]]; then
\r
784 echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"
\r
792 if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi
\r
794 # now use the function:
\r
795 parse_options $*</code></pre>
\r
799 <div class="sect1">
\r
800 <h2 id="_examples">EXAMPLES</h2>
\r
801 <div class="sectionbody">
\r
802 <div class="paragraph"><p>Available subsections are <strong>Aliases</strong>, <strong>Completion</strong>, <strong>Unsorted/Misc examples</strong>,
\r
803 <strong>(Recursive) Globbing - Examples</strong>, <strong>Modifiers usage</strong>, <strong>Redirection-Examples</strong>,
\r
804 <strong>ZMV-Examples</strong> and <strong>Module-Examples</strong>.</p></div>
\r
805 <div class="sect2">
\r
806 <h3 id="_aliases">ALIASES</h3>
\r
807 <div class="paragraph"><p>Suffix aliases are supported in zsh since version 4.2.0. Some examples:</p></div>
\r
808 <div class="listingblock">
\r
809 <div class="content">
\r
810 <pre><code>alias -s tex=vim
\r
812 alias -s org=w3m</code></pre>
\r
814 <div class="paragraph"><p>Now pressing return-key after entering <em>foobar.tex</em> starts vim with
\r
815 foobar.tex. Calling a html-file runs browser w3m. <em>www.zsh.org</em> and pressing
\r
816 enter starts w3m with argument www.zsh.org.<br />
\r
817 Global aliases can be used anywhere in the command line. Example:</p></div>
\r
818 <div class="listingblock">
\r
819 <div class="content">
\r
820 <pre><code>$ alias -g C='| wc -l'
\r
821 $ grep alias ~/.zsh/* C
\r
824 <div class="paragraph"><p>Some more or less useful global aliases (choose whether they are useful or not
\r
825 for you on your own):</p></div>
\r
826 <div class="listingblock">
\r
827 <div class="content">
\r
828 <pre><code>alias -g ...='../..'
\r
829 alias -g ....='../../..'
\r
830 alias -g .....='../../../..'
\r
831 alias -g CA="2>&1 | cat -A"
\r
832 alias -g C='| wc -l'
\r
833 alias -g D="DISPLAY=:0.0"
\r
834 alias -g DN=/dev/null
\r
835 alias -g ED="export DISPLAY=:0.0"
\r
836 alias -g EG='|& egrep'
\r
837 alias -g EH='|& head'
\r
838 alias -g EL='|& less'
\r
839 alias -g ELS='|& less -S'
\r
840 alias -g ETL='|& tail -20'
\r
841 alias -g ET='|& tail'
\r
842 alias -g F=' | fmt -'
\r
843 alias -g G='| egrep'
\r
844 alias -g H='| head'
\r
845 alias -g HL='|& head -20'
\r
846 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"
\r
847 alias -g LL="2>&1 | less"
\r
848 alias -g L="| less"
\r
849 alias -g LS='| less -S'
\r
850 alias -g MM='| most'
\r
851 alias -g M='| more'
\r
852 alias -g NE="2> /dev/null"
\r
853 alias -g NS='| sort -n'
\r
854 alias -g NUL="> /dev/null 2>&1"
\r
856 alias -g R=' > /c/aaa/tee.txt '
\r
857 alias -g RNS='| sort -nr'
\r
858 alias -g S='| sort'
\r
859 alias -g TL='| tail -20'
\r
860 alias -g T='| tail'
\r
861 alias -g US='| sort -u'
\r
862 alias -g VM=/var/log/messages
\r
863 alias -g X0G='| xargs -0 egrep'
\r
864 alias -g X0='| xargs -0'
\r
865 alias -g XG='| xargs egrep'
\r
866 alias -g X='| xargs'</code></pre>
\r
869 <div class="sect2">
\r
870 <h3 id="_completion">COMPLETION</h3>
\r
871 <div class="paragraph"><p>See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old
\r
872 style of zsh programmable completion, zshcompsys is the new completion
\r
873 system, zshcompwid are the zsh completion widgets.</p></div>
\r
874 <div class="paragraph"><p>Some functions, like _apt and _dpkg, are very slow. You can use a cache
\r
875 in order to proxy the list of results (like the list of available
\r
876 debian packages) Use a cache:</p></div>
\r
877 <div class="listingblock">
\r
878 <div class="content">
\r
879 <pre><code>zstyle ':completion:*' use-cache on
\r
880 zstyle ':completion:*' cache-path ~/.zsh/cache</code></pre>
\r
882 <div class="paragraph"><p>Prevent CVS files/directories from being completed:</p></div>
\r
883 <div class="listingblock">
\r
884 <div class="content">
\r
885 <pre><code>zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'
\r
886 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'</code></pre>
\r
888 <div class="paragraph"><p>Fuzzy matching of completions for when you mistype them:</p></div>
\r
889 <div class="listingblock">
\r
890 <div class="content">
\r
891 <pre><code>zstyle ':completion:*' completer _complete _match _approximate
\r
892 zstyle ':completion:*:match:*' original only
\r
893 zstyle ':completion:*:approximate:*' max-errors 1 numeric</code></pre>
\r
895 <div class="paragraph"><p>And if you want the number of errors allowed by _approximate to
\r
896 increase with the length of what you have typed so far:</p></div>
\r
897 <div class="listingblock">
\r
898 <div class="content">
\r
899 <pre><code>zstyle -e ':completion:*:approximate:*' \
\r
900 max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'</code></pre>
\r
902 <div class="paragraph"><p>Ignore completion functions for commands you don’t have:</p></div>
\r
903 <div class="listingblock">
\r
904 <div class="content">
\r
905 <pre><code>zstyle ':completion:*:functions' ignored-patterns '_*'</code></pre>
\r
907 <div class="paragraph"><p>With helper functions like:</p></div>
\r
908 <div class="listingblock">
\r
909 <div class="content">
\r
910 <pre><code>xdvi() { command xdvi ${*:-*.dvi(om[1])} }</code></pre>
\r
912 <div class="paragraph"><p>you can avoid having to complete at all in many cases, but if you do,
\r
913 you might want to fall into menu selection immediately and to have the
\r
914 words sorted by time:</p></div>
\r
915 <div class="listingblock">
\r
916 <div class="content">
\r
917 <pre><code>zstyle ':completion:*:*:xdvi:*' menu yes select
\r
918 zstyle ':completion:*:*:xdvi:*' file-sort time</code></pre>
\r
920 <div class="paragraph"><p>Completing process IDs with menu selection:</p></div>
\r
921 <div class="listingblock">
\r
922 <div class="content">
\r
923 <pre><code>zstyle ':completion:*:*:kill:*' menu yes select
\r
924 zstyle ':completion:*:kill:*' force-list always</code></pre>
\r
926 <div class="paragraph"><p>If you end up using a directory as argument, this will remove the
\r
927 trailing slash (useful in ln)</p></div>
\r
928 <div class="listingblock">
\r
929 <div class="content">
\r
930 <pre><code>zstyle ':completion:*' squeeze-slashes true</code></pre>
\r
932 <div class="paragraph"><p>cd will never select the parent directory (e.g.: cd ../<TAB>):</p></div>
\r
933 <div class="listingblock">
\r
934 <div class="content">
\r
935 <pre><code>zstyle ':completion:*:cd:*' ignore-parents parent pwd</code></pre>
\r
937 <div class="paragraph"><p>Another method for <em>quick change directories</em>. Add this to your ~/.zshrc, then just enter
\r
938 “cd …./dir”</p></div>
\r
939 <div class="listingblock">
\r
940 <div class="content">
\r
941 <pre><code>rationalise-dot() {
\r
942 if [[ $LBUFFER = *.. ]]; then
\r
948 zle -N rationalise-dot
\r
949 bindkey . rationalise-dot</code></pre>
\r
952 <div class="sect2">
\r
953 <h3 id="_unsorted_misc_examples">UNSORTED/MISC examples</h3>
\r
954 <div class="paragraph"><p>Hint: A list of valid glob Qualifiers can be found in zshexpn(1).
\r
955 See “man 1 zshexpn | less -p” Qualifiers for details.</p></div>
\r
956 <div class="listingblock">
\r
957 <div class="content">
\r
958 <pre><code># Get the names of all files that *don't* match a pattern *anywhere* on the
\r
959 # file (and without ``-L'' because its GNUish)
\r
960 $ print -rl -- *(.^e{'grep -q pattern $REPLY'})
\r
962 $ : *(.e{'grep -q pattern $REPLY || print -r -- $REPLY'})
\r
965 $ echo $[${RANDOM}%1000] # random between 0-999
\r
966 $ echo $[${RANDOM}%11+10] # random between 10-20
\r
967 $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)
\r
970 $ echo "${(j::)${(@Oa)${(s::):-hello}}}"
\r
972 # Show newest directory
\r
975 # random array element
\r
976 $ FILES=( .../files/* )
\r
977 $ feh $FILES[$RANDOM%$#FILES+1]
\r
979 # cat first line in all files in this dir
\r
980 $ for file (*(ND-.)) IFS= read -re < $file
\r
982 # test if a parameter is numeric
\r
983 $ if [[ $1 == <-> ]] ; then
\r
989 # Show me all the .c files for which there doesn't exist a .o file.
\r
990 $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)
\r
992 # All files in /var/ that are not owned by root
\r
993 $ ls -ld /var/*(^u:root)
\r
995 # All files for which the owner hat read and execute permissions
\r
998 # The same, but also others don't have execute permissions
\r
999 $ echo *(f:u+rx,o-x:)
\r
1001 # brace expansion - example
\r
1004 $ print -r -- $^X.$^Y
\r
1005 A.+ A.- B.+ B.- C.+ C.-
\r
1007 # Fetch the newest file containing the string 'fgractg*.log' in the
\r
1008 # filename and contains the string 'ORA-' in it
\r
1009 $ file=(fgractg*.log(Nm0om[1]))
\r
1010 $ (($#file)) && grep -l ORA- $file
\r
1012 $ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
\r
1013 > if [ -n "$files" ]; then
\r
1017 > file=$(ls -td $files | head -1)
\r
1018 > grep -l ORA- "$file"
\r
1021 # keep specified number of child processes running until entire task finished
\r
1022 $ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
\r
1024 # Remove zero length and .bak files in a directory
\r
1025 $ rm -i *(.L0) *.bak(.)
\r
1027 # print out files that don't have extensions
\r
1028 $ printf '%s\n' ^?*.*
\r
1029 $ printf '%s\n' ^?*.[^.]*(D)
\r
1030 $ ls -d -- ^?*.*(D)
\r
1032 # Finding files which does not contain a specific string
\r
1033 $ print -rl file* | comm -2 -3 - <(grep -l string file*)'
\r
1034 $ for f (file*(N)) grep -q string $f || print -r $f'
\r
1036 # Show/Check whether a option is set or not. It works both with $options as
\r
1038 $ echo $options[correct]
\r
1043 # Count the number of directories on the stack
\r
1044 $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
\r
1045 $ dirs -v | awk '{n=$1}END{print n+1}'
\r
1047 # Matching all files which do not have a dot in filename
\r
1050 # Show only the ip-address from ``ifconfig device''
\r
1051 # ifconfig from net-tools (Linux)
\r
1052 $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}
\r
1053 # ifconfig from 4.2BSD {Free,Net,Open}BSD
\r
1054 $ print ${$(/sbin/ifconfig tun0)[6]}
\r
1056 # Ping all the IP addresses in a couple of class C's or all hosts
\r
1058 $ for i in {1..254}; do ping -c 1 192.168.13.$i; done
\r
1061 $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done
\r
1063 $ for i in $(sed 's/#.*//' > /etc/hosts | awk '{print $2}')
\r
1065 : echo "Trying $i ... "
\r
1067 : echo '============================='
\r
1070 # load all available modules at startup
\r
1073 $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
\r
1076 # Rename all files within a directory such that their names get a numeral
\r
1077 # prefix in the default sort order.
\r
1078 $ i=1; for j in *; do mv $j $i.$j; ((i++)); done
\r
1079 $ i=1; for f in *; do mv $f $(echo $i | \
\r
1080 awk '{ printf("%03d", $0)}').$f; ((i++)); done
\r
1081 $ integer i=0; for f in *; do mv $f $[i+=1].$f; done
\r
1083 # Find (and print) all symbolic links without a target within the current
\r
1085 $ $ file **/*(D@) | fgrep broken
\r
1086 $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
\r
1087 $ echo **/*(@-^./=%p)
\r
1088 $ print -l **/*(-@)
\r
1090 # List all plain files that do not have extensions listed in `fignore'
\r
1091 $ ls **/*~*(${~${(j/|/)fignore}})(.)
\r
1092 # see above, but now omit executables
\r
1093 $ ls **/*~*(${~${(j/|/)fignore}})(.^*)
\r
1095 # Print out files that don't have extensions (require *setopt extendedglob*
\r
1096 # and *setopt dotglob*)
\r
1097 $ printf '%s\n' ^?*.*
\r
1099 # List files in reverse order sorted by name
\r
1100 $ print -rl -- *(On)
\r
1102 $ print -rl -- *(^on)
\r
1104 # Synonymic to ``ps ax | awk '{print $1}'''
\r
1105 $ print -l /proc/*/cwd(:h:t:s/self//)
\r
1107 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
\r
1111 > for i in /proc/<->/stat
\r
1113 > [[ "$(< $i)" = *\((${(j:|:)~@})\)* ]] && echo $i:h:t
\r
1117 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...
\r
1118 $ for (( i = 36#n; i <= 36#y; i++ )); do
\r
1119 > print ${$(([##36]i)):l}
\r
1121 # or in combination with ``dc''
\r
1122 $ print {$((##n))..$((##y))}P\ 10P | dc
\r
1123 # or with ``eval''
\r
1124 $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'
\r
1126 # foreach in one line of shell
\r
1127 $ for f (*) print -r -- $f
\r
1129 # copy a directory recursively without data/files
\r
1131 $ cd -- $dest_root
\r
1132 $ mkdir -p -- $dirs
\r
1134 $ find . -type d -exec env d="$dest_root" \
\r
1135 sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
\r
1137 # If `foo=23'', then print with 10 digit with leading '0'.
\r
1139 $ print ${(r:10::0:)foo}
\r
1141 # find the name of all the files in their home directory that have
\r
1142 # 20 or more characters in their file names
\r
1143 print -rl $HOME/${(l:20::?:)~:-}*
\r
1146 $ print -r -- ${(qq)m} > $nameoffile # save it
\r
1147 $ eval "m=($(cat -- $nameoffile)" # or use
\r
1148 $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
\r
1150 # get a "ls -l" on all the files in the tree that are younger than a
\r
1151 # specified age (e.g "ls -l" all the files in the tree that where
\r
1152 # modified in the last 2 days)
\r
1153 $ ls -tld **/*(m-2)
\r
1154 # This will give you a listing 1 file perl line (not à la ls -R).
\r
1155 # Think of an easy way to have a "ls -R" style output with
\r
1156 # only files newer than 2 day old.
\r
1157 $ for d (. ./**/*(/)) {
\r
1158 > print -r -- $'\n'${d}:
\r
1159 > cd $d && {
\r
1161 > (($#l)) && ls -ltd -- $l
\r
1165 # If you also want directories to be included even if their mtime
\r
1166 # is more than 2 days old:
\r
1167 $ for d (. ./**/*(/)) {
\r
1168 > print -r -- $'\n'${d}:
\r
1169 > cd $d && {
\r
1170 > l=(*(N/,m-2))
\r
1171 > (($#l)) && ls -ltd -- $l
\r
1175 # And if you want only the directories with mtime < 2 days to be listed:
\r
1176 $ for d (. ./**/*(N/m-2)) {
\r
1177 > print -r -- $'\n'${d}:
\r
1178 > cd $d && {
\r
1180 > (($#l)) && ls -ltd -- $l
\r
1186 $ echo ${(l:42::-:)}
\r
1187 # or use ``$COLUMS''
\r
1188 $ echo ${(l:$COLUMNS::-:)}
\r
1189 # and now with colors (require autoload colors ;colors)
\r
1190 $ echo "$bg[red]$fg[black]${(l:42::-:)}"
\r
1192 # Redirect STDERR to a command like xless without redirecting STDOUT as well.
\r
1193 $ foo 2>>(xless)
\r
1194 # but this executes the command asynchronously. To do it synchronously:
\r
1195 $ { { foo 1>&3 } 2>&1 | xless } 3>&1
\r
1197 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3
\r
1198 $ for i in *.mp3; do
\r
1199 > mv $i ${${(C)i}:s/Mp3/mp3/}
\r
1202 # Match file names containing only digits and ending with .xml (require
\r
1203 # *setopt kshglob*)
\r
1204 $ ls -l [0-9]##.xml
\r
1205 $ ls -l <0->.xml
\r
1207 # Remove all "non txt" files
\r
1210 # Move 200 files from a directory into another
\r
1211 $ mv -- *([1,200]) /another/Dir
\r
1213 # Convert images (foo.gif => foo.png):
\r
1214 $ for i in **/*.gif; convert $i $i:r.png
\r
1216 # convert a collection of mp3 files to wave or cdr,
\r
1217 # e.g. file.wav -> file.mp3)
\r
1218 $ for i (./*.mp3){mpg321 --w - $i > ${i:r}.wav}
\r
1220 # Download with LaTeX2HTML created Files (for example the ZSH-Guide):
\r
1221 $ for f in https://zsh.sourceforge.io/Guide/zshguide{,{01..08}}.html; do
\r
1222 > lynx -source $f >${f:t}
\r
1225 # Move all files in dir1 and dir2 that have line counts greater than 10 to
\r
1226 # another directory say "/more10"
\r
1227 $ mv dir[12]/**/*.cr(-.e{'((`wc -l < $REPLY` > 10))'}) /more10
\r
1229 # Make with dpkg a master-list of everyfile that it has installed
\r
1230 $ diff <(find / | sort) <(cat /var/lib/dpkg/info/*.list | sort)
\r
1232 # Replace this fucking Escape-Sequences:
\r
1233 $ autoload colors ; colors
\r
1234 $ print "$bg[cyan]$fg[blue]You are a idiot" >> /dev/pts/3
\r
1236 # Get ASCII value of a character
\r
1237 $ char=N ; print $((#char))
\r
1239 # Filename "Erweiterung"
\r
1240 # Note: The (N) says to use the nullglob option for this particular
\r
1242 $ for i in *.o(N); do
\r
1246 # Rename files; i. e. FOO to foo and bar to BAR
\r
1247 $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'
\r
1248 $ for i in *(.); mv $i ${i:u} # `bar to `BAR'
\r
1250 # Show all suid-files in $PATH
\r
1251 $ ls -latg ${(s.:.)PATH} | grep '^...s'
\r
1252 # or more complex ;)
\r
1253 $ print -l ${^path}/*(Ns,S)
\r
1254 # or show only executables with a user given pattern
\r
1255 $ print -l ${^path}/*vim*(*N)
\r
1257 # gzip files when containing a certain string
\r
1258 $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}
\r
1260 # A small one-liner, that reads from stdin and prints to stdout the first
\r
1261 # unique line i. e. does not print lines that have been printed before
\r
1262 # (this is similar to the unique command, but unique can only handle
\r
1263 # adjacent lines).
\r
1264 $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}
\r
1266 # Lists every executable in PATH
\r
1267 $ print -l ${^path}/*(-*N)
\r
1269 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?
\r
1270 $ ls **/*.c~(*/)#SCCS/*
\r
1272 # List all `README' - files case-insensitive with max. one typo
\r
1273 $ ls **/*(#ia2)readme
\r
1275 # case insensitive checking for variables
\r
1276 $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then
\r
1277 > echo "Penguin on board."
\r
1279 > echo "Not a Linux."
\r
1280 > fi</code></pre>
\r
1283 <div class="sect2">
\r
1284 <h3 id="_recursive_globbing_examples">(Recursive) Globbing - Examples</h3>
\r
1285 <div class="paragraph"><p>A list of valid glob Qualifiers can be found in zshexpn(1). <strong>Note:</strong>
\r
1286 **/ is equivalent to (*/)#! For example:</p></div>
\r
1287 <div class="listingblock">
\r
1288 <div class="content">
\r
1289 <pre><code>$ print (*/)#zsh_us.ps
\r
1290 zsh-4.2.3/Doc/zsh_us.ps
\r
1291 $ print **/zsh_us.ps
\r
1292 zsh-4.2.3/Doc/zsh_us.ps</code></pre>
\r
1294 <div class="listingblock">
\r
1295 <div class="content">
\r
1296 <pre><code># Search for `README' in all Subdirectories
\r
1299 # find directories that contain both "index.php" and "index.html", or in
\r
1300 # general, directories that contain more than one file matching "index.*"
\r
1301 $ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
\r
1303 $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l >= 2 ))':)
\r
1305 # Find command to search for directory name instead of basename
\r
1306 $ print -rl /**/*~^*/path(|/*)
\r
1307 # or - without Zsh
\r
1308 $ find / | grep -e /path/ -e '/path$'
\r
1310 # Print he path of the directories holding the ten biggest C regular files
\r
1311 # in the current directory and subdirectories.
\r
1312 $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
\r
1314 # Find files with size == 0 and send a mail
\r
1315 $ files=(**/*(ND.L0m+0m-2))
\r
1316 > (( $#files > 0 )) && print -rl -- $files | \
\r
1317 mailx -s "empty files" foo@bar.tdl
\r
1320 $ chmod 700 **/(.) # Only files
\r
1321 $ chmod 700 **/(/) # Only directories
\r
1323 # print out all of the files in that directory in 2 columns
\r
1324 $ print -rC2 -- ${1:[...]}/*(D:t)
\r
1325 # ^- number ob columns
\r
1326 # or - if you feel concerned about special characters - use
\r
1327 $ list=(${1:[...]}/*(ND:t))
\r
1328 $ (($#list)) && print -rC2 -- ${(V)list}
\r
1330 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
\r
1331 # (recursive, include dotfiles) remove the setgid/setuid flag and print
\r
1333 $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))
\r
1334 # or with a small script
\r
1335 $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {
\r
1336 > print -r -- $file
\r
1337 > chmod -s $file && print -r fixed $file
\r
1339 # or use ``zargs'' (require autoload zargs) prevent the arg list too
\r
1341 $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
\r
1343 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
\r
1344 $ ls -l foo<23->
\r
1346 # get all files that begin with the date strings from June 4 through
\r
1348 $ ls -l 200406{04..10}*(N)
\r
1349 # or if they are of the form 200406XX (require ``setopt extended_glob''
\r
1350 $ ls -l 200306<4-10>.*
\r
1352 # remove spaces from filenames
\r
1353 $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
\r
1355 # Show only all *.c and *.h - Files
\r
1358 # Show only all *.c - files and ignore `foo.c'
\r
1361 # show data to *really* binary format
\r
1362 $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \
\r
1363 > {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' < binary
\r
1365 # Show only world-readable files
\r
1368 # List files in the current directory are not writable by the owner
\r
1369 $ print -l ~/*(ND.^w)
\r
1371 # find and delete the files which are older than a given parameter
\r
1372 # (seconds/minutes/hours)
\r
1373 # deletes all regular file in /Dir that are older than 3 hours
\r
1374 $ rm -f /Dir/**/*(.mh+3)
\r
1375 # deletes all symlinks in /Dir that are older than 3 minutes
\r
1376 $ rm -f /Dir/**/*(@mm+3)
\r
1377 # deletes all non dirs in /Dir that are older than 30 seconds
\r
1378 $ rm -f /Dir/**/*(ms+30^/)
\r
1379 # deletes all folders, sub-folders and files older than one hour
\r
1380 $ rm ./**/*(.Dmh+1,.DL0)
\r
1381 # deletes all files more than 6 hours old
\r
1382 $ rm -f **/*(mh+6)
\r
1383 # removes all files but the ten newer ones (delete all but last 10
\r
1384 # files in a directory)
\r
1385 $ rm ./*(Om[1,-11])
\r
1386 Note: If you get a arg list too long, you use the builtin rm. For
\r
1388 $ zmodload zsh/files ; rm -f **/*(mh+6)
\r
1389 or use the zargs function:
\r
1390 $ autoload zargs ; zargs **/*(mh+6) -- rm -f
\r
1392 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
\r
1393 # Matching find all files in all subdirectories, searching recursively,
\r
1394 # which have a given name, case insensitive, are at least 50 KB large,
\r
1395 # no more than a week old and owned by the root user, and allowing up
\r
1396 # to a single error in the spelling of the name. In fact, the required
\r
1397 # expression looks like this:
\r
1398 $ ls **/(#ia1)name(LK+50mw-1u0)
\r
1400 # Change the UID from 102 to 666
\r
1401 $ chown 666 **/*(u102)
\r
1403 # List all files which have not been updated since last 10 hours
\r
1404 $ print -rl -- *(Dmh+10^/)
\r
1406 # delete only the oldest file in a directory
\r
1407 $ rm ./*filename*(Om[1])
\r
1409 # Sort the output from `ls -l' by file size
\r
1412 # find most recent file in a directory
\r
1413 $ setopt dotglob ; print directory/**/*(om[1])
\r
1415 # Show only empty files which nor `group' or `world writable'
\r
1418 # Find - and list - the ten newest files in directories and subdirs.
\r
1420 $ print -rl -- **/*(Dom[1,10])
\r
1422 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'').
\r
1423 $ ls -fl *(DOL[1,5])
\r
1425 # Display the 5-10 last modified files.
\r
1426 $ print -rl -- /path/to/dir/**/*(D.om[5,10])
\r
1428 # Find all files without a valid owner.
\r
1429 $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
\r
1431 # Find all the empty directories in a tree.
\r
1432 $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
\r
1433 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
\r
1434 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all
\r
1435 # subdirectories with no entries.
\r
1438 # Remove empty directories afterwards.
\r
1439 $ rmdir ./**/*(/od) 2> /dev/null
\r
1441 # Show only files which are owned by group `users'.
\r
1442 $ ls -l *(G[users])</code></pre>
\r
1445 <div class="sect2">
\r
1446 <h3 id="_modifiers_usage">Modifiers usage</h3>
\r
1447 <div class="paragraph"><p>Modifiers are a powerful mechanism that let you modify the results
\r
1448 returned by parameter, filename and history expansion. See zshexpn(1)
\r
1449 for details.</p></div>
\r
1450 <div class="listingblock">
\r
1451 <div class="content">
\r
1452 <pre><code># NOTE: Zsh 4.3.4 needed!
\r
1454 # files modified today
\r
1455 $ print *(e:age today now:)
\r
1456 # files modified since 5 pm
\r
1457 $ print *(e-age 17:00 now-)
\r
1458 # ... since 5 o'clock yesterda
\r
1459 $ print *(e-age yesterday,17:00 now-)
\r
1460 # ... from last Christmas before today
\r
1461 $ print *(e-age 2006/12/25 today-)
\r
1462 # ... before yesterday
\r
1463 $ print *(e-age 1970/01/01 yesterday-)
\r
1464 # all files modified between the start of those dates
\r
1465 $ print *(e:age 2006/10/04 2006/10/09:)
\r
1466 # all files modified on that date
\r
1467 $ print *(e:age 2006/10/04:)
\r
1469 $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)
\r
1471 # Remove a trailing pathname component, leaving the head. This works like
\r
1476 # Remove all leading pathname components, leaving the tail. This works
\r
1477 # like `basename'.
\r
1481 # Remove the suffix from each file (*.sh in this example)
\r
1482 $f:e is $f file extension
\r
1483 :h --> head (dirname)
\r
1484 :t --> tail (basename)
\r
1485 :r --> rest (extension removed)
\r
1486 $ for f (*.sh) mv $f $f:r
\r
1488 # Remove a filename extension of the form `.xxx', leaving the root name.
\r
1494 # Remove all but the extension.
\r
1501 # Print the new command but do not execute it. Only works with history
\r
1508 # Quote the substituted words, escaping further substitutions.
\r
1515 # Convert the words to all lowercase.
\r
1522 # Convert the words to all uppercase.
\r
1529 # convert 1st char of a word to uppercase
\r
1530 $ foo="one two three four"
\r
1531 $ print -r -- "${(C)foo}"
\r
1532 One Two Three Four</code></pre>
\r
1535 <div class="sect2">
\r
1536 <h3 id="_redirection_examples">Redirection-Examples</h3>
\r
1537 <div class="paragraph"><p>See zshmisc(1) for more information (or less ${^fpath}/zmv(N))</p></div>
\r
1538 <div class="listingblock">
\r
1539 <div class="content">
\r
1540 <pre><code># Append `exit 1' at the end of all *.sh - files
\r
1541 $ echo "exit 1" >> *.sh
\r
1543 # adding files to foobar.tar.gz
\r
1544 $ eval set =(gunzip < foobar.tar.gz) '
\r
1545 tar rf $1 additional.txt &&gzip < $1 > foobar.tar.gz'
\r
1547 # Redirect output to a file AND display on screen
\r
1548 $ foobar >&1 > file1 > file2 > ..
\r
1550 # pipe single output to multiple inputs
\r
1551 $ zcat foobar.Z >> (gzip -9 > file1.gz) \
\r
1552 >> (bzip2 -9 > file1.bz2) \
\r
1553 >> (acb --best > file1.acb)
\r
1555 # Append /etc/services at the end of file `foo' and `bar'
\r
1556 $ cat /etc/services >> foo >> bar
\r
1559 $ echo An error >&2 2>&1 | sed -e 's/A/I/'
\r
1561 # send standard output of one process to standard input of several processes
\r
1564 $ process1 > >(process1) > >(process2)
\r
1566 # initializing a variable and simultaneously keeping terminal output
\r
1568 $ { a=$(command >&1 >& 3 3 > &- 2>&1);} 3>&1
\r
1570 # redirect stderr two times
\r
1571 $ setopt multios ; program 2> file2 > file1 2>&1
\r
1573 # Duplicating stdout and stderr to a logfile
\r
1574 $ exec 3>&1 > logfile 2>&2 2>&1 >&3 3>&-
\r
1576 # redirect stderr (only) to a file and to orig. stderr:
\r
1577 $ command 2>&2 2>stderr
\r
1578 # redirect stderr and stdout to separate files and both to orig. stdout:
\r
1579 $ command 2>&1 1>&1 2>stderr 1>stdout
\r
1580 # redirect stderr and stdout to separate files and stdout to orig. stdout
\r
1581 # AND stderr to orig. stderr:
\r
1582 $ command 2>&2 1>&1 2>stderr 1>stdout
\r
1584 # More fun with STDERR ;)
\r
1585 $ ./my-script.sh 2> >(grep -v moron >error.log)|process-output >output.log
\r
1586 $ echo "Thats STDOUT" >>(sed 's/stdout/another example/' > foobar)</code></pre>
\r
1589 <div class="sect2">
\r
1590 <h3 id="_zmv_examples_require_autoload_zmv">ZMV-Examples (require autoload zmv)</h3>
\r
1591 <div class="paragraph"><p><strong>Note:</strong> <em>-n</em> means no execution (just print what would happen). At</p></div>
\r
1592 <div class="listingblock">
\r
1593 <div class="content">
\r
1594 <pre><code># Remove illegal characters in a fat32 file system. Illegal characters are
\r
1595 # / : ; * ? " < > |
\r
1596 # NOTE: ``-Q'' and (D) is to include hidden files.
\r
1597 $ unwanted='[:;*?\"<>|]'
\r
1598 $ zmv -Q "(**/)(*$~unwanted*)(D)" '$1${2//$~unwanted/}'
\r
1600 # Changing part of a filename (i. e. "file-hell.name" -> "file-heaven.name")
\r
1601 $ zmv '(*)hell(*)' '${1}heaven${2}'
\r
1603 $ zmv '*' '$f:s/hell/heaven/'
\r
1605 # remove round bracket within filenames
\r
1606 # i. e. foo-(bar).avi -> foo-bar.avi
\r
1607 $ zmv '*' '${f//[()]/}'
\r
1609 # serially all files (foo.foo > 1.foo, fnord.foo > 2.foo, ..)
\r
1612 1.c asd.foo bla.foo fnord.foo foo.fnord foo.foo
\r
1613 $ c=1 zmv '*.foo' '$((c++)).foo'
\r
1615 1.c 1.foo 2.foo 3.foo 4.foo foo.fnord
\r
1617 # Rename "file.with.many.dots.txt" by substituting dots (except for the last
\r
1618 # one!) with a space
\r
1619 $ touch {1..20}-file.with.many.dots.txt
\r
1620 $ zmv '(*.*)(.*)' '${1//./ }$2'
\r
1622 # Remove the first 4 chars from a filename
\r
1623 $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
\r
1625 # Rename names of all files under the current Dir to lower case, but keep
\r
1627 $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
\r
1629 # replace all 4th character, which is "1", with "2" and so on
\r
1631 $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'
\r
1633 # Remove the first 15 characters from a string
\r
1634 $ touch 111111111111111{a-z}
\r
1636 $ zmv '*' '$f[16,-1]'
\r
1638 # Replace spaces (any number of them) with a single dash in file names
\r
1640 $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'
\r
1642 $ find . -depth -name '* *' -exec bash -c '
\r
1643 > shopt -s extglob
\r
1645 > dir=${file%/*}
\r
1646 > name=${file##*/}
\r
1647 > newname=${name//*([ -]) *([ -])/-}
\r
1648 > mv -i -- "$file" "$Dir/$newname"' {} {} \;
\r
1650 # Clean up file names and remove special characters
\r
1652 $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'
\r
1654 # Add *.py to a bunch of python scripts in a directory (some of them end
\r
1655 # in *.py and give them all a proper extension
\r
1657 $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
\r
1659 # lowercase all extensions (i. e. *.JPG) incl. subfolders
\r
1661 $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
\r
1662 # Or - without Zsh
\r
1663 $ find Dir -name '*.[jJ][pP][gG]' -print | while read f
\r
1667 > *) mv "$f" "${f%.*}.jpg" ;
\r
1671 # remove leading zeros from file extension
\r
1674 filename.001 filename.003 filename.005 filename.007 filename.009
\r
1675 filename.002 filename.004 filename.006 filename.008 filename.010
\r
1676 $ zmv '(filename.)0##(?*)' '$1$2'
\r
1678 filename.1 filename.10 filename.2 filename.3 filename.4 filename.5 ..
\r
1683 foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
\r
1684 $ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
\r
1686 foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
\r
1688 # adding leading zeros to a filename (1.jpg -> 001.jpg, ..
\r
1690 $ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
\r
1692 # See above, but now only files with a filename >= 30 chars
\r
1694 $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'
\r
1696 # Replace spaces in filenames with a underline
\r
1698 $ zmv '* *' '$f:gs/ /_'
\r
1700 # Change the suffix from *.sh to *.pl
\r
1702 $ zmv -W '*.sh' '*.pl'
\r
1704 # Add a "".txt" extension to all the files within ${HOME}
\r
1705 # ``-.'' is to only rename regular files or symlinks to regular files,
\r
1706 # ``D'' is to also rename hidden files (dotfiles))
\r
1708 $ zmv -Q '/home/**/*(D-.)' '$f.txt'
\r
1709 # Or to only rename files that don't have an extension:
\r
1710 $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
\r
1712 # Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
\r
1714 $ chars='[][?=+<>;",*-]'
\r
1715 $ zmv '(**/)(*)' '$1${2//$~chars/%}'
\r
1717 # Removing single quote from filenames (recursively)
\r
1719 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1721 # When a new file arrives (named file.txt) rename all files in order to
\r
1722 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes
\r
1723 # file119.txt and so on ending with file.txt becoming file1.txt
\r
1725 $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'
\r
1727 # lowercase/uppercase all files/directories
\r
1729 $ zmv '(*)' '${(L)1}' # lowercase
\r
1730 $ zmv '(*)' '${(U)1}' # uppercase
\r
1732 # Remove the suffix *.c from all C-Files
\r
1734 $ zmv '(*).c' '$1'
\r
1736 # Uppercase only the first letter of all *.mp3 - files
\r
1738 $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
\r
1740 # Copy the target `README' in same directory as each `Makefile'
\r
1742 $ zmv -C '(**/)Makefile' '${1}README'
\r
1744 # Removing single quote from filenames (recursively)
\r
1746 $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
\r
1748 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
\r
1750 $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
\r
1751 $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively</code></pre>
\r
1754 <div class="sect2">
\r
1755 <h3 id="_module_examples">Module-Examples</h3>
\r
1756 <div class="paragraph"><p>Please read zshmodules(1) first!</p></div>
\r
1757 <div class="sect3">
\r
1758 <h4 id="_zsh_pcre_require_zmodload_zsh_pcre">zsh/pcre (require zmodload zsh/pcre)</h4>
\r
1759 <div class="listingblock">
\r
1760 <div class="content">
\r
1761 <pre><code># Copy files of a certain period (date indicated in the filenames)
\r
1762 $ zmodload zsh/pcre
\r
1763 $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)
\r
1765 $ m() { [[ $1 -pcre-match pcre-regexp ]] }
\r
1766 $ ls -d -- *(+m)</code></pre>
\r
1769 <div class="sect3">
\r
1770 <h4 id="_zsh_clone_require_zmodload_zsh_clone">zsh/clone (require zmodload zsh/clone)</h4>
\r
1771 <div class="listingblock">
\r
1772 <div class="content">
\r
1773 <pre><code># Creates a forked instance of the current shell ($! is set to zero) and
\r
1774 # execute ``command'' on /dev/tty8 (for this example).
\r
1775 $ zmodload zsh/clone
\r
1776 $ clone /dev/tty8 && (($! == 0)) && exec command</code></pre>
\r
1779 <div class="sect3">
\r
1780 <h4 id="_zsh_datetime_require_zmodload_zsh_datetime">zsh/datetime (require zmodload zsh/datetime)</h4>
\r
1781 <div class="listingblock">
\r
1782 <div class="content">
\r
1783 <pre><code> $ zmodload zsh/datetime
\r
1784 $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'
\r
1785 $ export DATE=`datereplacement`
\r
1788 # strip date from filename
\r
1789 $ $ zmodload zsh/datetime
\r
1790 $ setopt extendedglob
\r
1791 $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat
\r
1792 $ strftime -s pattern \
\r
1793 '???_???_<0-%Y%m%d>_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))
\r
1794 $ print -rl -- $~pattern
\r
1795 aaa_bbb_20041212_c.dat
\r
1796 $ print -rl -- $pattern
\r
1797 ???_???_<0-20050815>_?.dat
\r
1799 # Search files size == 0, to be based on the file name containing a date
\r
1800 # rather than the "last modified" date of the file
\r
1801 $ zmodload -i zsh/datetime
\r
1802 $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
\r
1803 $ files=(**/$file(N.L0))
\r
1804 $ (( $#files > 0 )) && print -rl -- $files | \
\r
1805 mailx -s "empty files" foo@bar.tdl</code></pre>
\r
1808 <div class="sect3">
\r
1809 <h4 id="_zsh_stat_require_zmodload_zsh_stat">zsh/stat (require zmodload zsh/stat)</h4>
\r
1810 <div class="listingblock">
\r
1811 <div class="content">
\r
1812 <pre><code># test if a symbolic link links to a certain file
\r
1813 $ zmodload -i zsh/stat
\r
1814 $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln
\r
1816 # comparing file dates
\r
1817 $ zmodload zsh/stat
\r
1820 $ touch bar & sleep 5 & touch foo
\r
1821 $ echo $file1 is $(($(stat +mtime $file2) - \
\r
1822 $(stat +mtime $file1))) seconds older than $file2.
\r
1823 bar is 5 seconds older than foo
\r
1825 # list the files of a disk smaller than some other file
\r
1826 $ zmodload zsh/stat
\r
1827 $ stat -A max +size some-other-file
\r
1828 $ print -rl ./**/*(D.L-$max)
\r
1830 # List the top 100 biggest files in a disk
\r
1831 $ zmodload zsh/stat
\r
1832 $ ls -fld ./**/*(d`stat +device .`OL[1,100])
\r
1834 # Get only the user name and the file names from (like
\r
1835 # ls -l * | awk '{print $3" " $8}')
\r
1836 $ zmodload zsh/stat
\r
1838 > stat -sA user +uid -- "$file" &&
\r
1839 > print -r -- "$user" "$file"
\r
1842 # get the difference between actual bytes of file and allocated bytes of file
\r
1843 $ zmodload zsh/stat
\r
1844 $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))
\r
1846 # Find largest file
\r
1847 # ``D'' : to include dot files (d lowercase is for device)
\r
1848 # ``O'' : reverse Ordered (o lowercase for non-reverse order)
\r
1849 # ``L'' : by file Length (l is for number of links)
\r
1850 # ``[1]'': return only first one
\r
1851 $ zmodload zsh/stat
\r
1852 $ stat +size ./*(DOL[1])
\r
1854 # file size in bytes
\r
1855 $ zmodload zsh/stat
\r
1856 $ stat -L +size ~/.zshrc
\r
1859 # Delete files in a directory that hasn't been accessed in the last ten days
\r
1860 # and send ONE mail to the owner of the files informing him/her of the files'
\r
1862 $ zmodload zsh/stat zsh/files
\r
1863 $ typeset -A f; f=()
\r
1864 $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
\r
1865 $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
\r
1867 # Get a "ls -l" on all the files in the tree that are younger than a
\r
1869 $ zmodload zsh/stat
\r
1870 $ for d (. ./**/*(N/m-2))
\r
1871 > print -r -- $'\n'$d: && cd $d && {
\r
1872 > for f (*(Nm-2om))
\r
1873 > stat -F '%b %d %H:%M' -LsAs -- $f &&
\r
1874 > print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \
\r
1875 > ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-> $s[14]}
\r
1879 # get file creation date
\r
1880 $ zmodload zsh/stat
\r
1881 $ stat -F '%d %m %Y' +mtime ~/.zshrc
\r
1883 $ stat -F '%D' +mtime ~/.zshrc
\r
1884 06/30/04</code></pre>
\r
1887 <div class="sect3">
\r
1888 <h4 id="_zsh_files_require_zmodload_zsh_files">zsh/files (require zmodload zsh/files)</h4>
\r
1889 <div class="listingblock">
\r
1890 <div class="content">
\r
1891 <pre><code># search a directory for files containing a certain string then copy those
\r
1892 # files to another directory.
\r
1893 $ zmodload zsh/files
\r
1895 $ cp $(grep -lZr foobar .) otherdirectory</code></pre>
\r
1898 <div class="sect3">
\r
1899 <h4 id="_zsh_mapfile_require_zmodload_zsh_mapfile">zsh/mapfile (require zmodload zsh/mapfile)</h4>
\r
1900 <div class="listingblock">
\r
1901 <div class="content">
\r
1902 <pre><code># grepping for two patterns
\r
1903 $ zmodload zsh/mapfile
\r
1905 $ pattern2="bar foo"
\r
1906 $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] && [[ $z = *$pattern1* && \
\r
1907 $z = *$pattern2* ]]'})
\r
1908 # or a solution in combination with zsh/pcre
\r
1909 $ zmodload -i zsh/mapfile zsh/pcre
\r
1911 $ pattern2="bar foo"
\r
1912 $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"
\r
1914 $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})
\r
1916 # equivalent for ``less /etc/passwd | grep -v root''
\r
1917 $ zmodload zsh/mapfile
\r
1919 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}
\r
1920 # or - for case insensitive
\r
1921 $ setopt extendedglob
\r
1922 $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
\r
1924 # If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
\r
1925 # this empty tags (ones ending in '/>') so if encountered in the same
\r
1926 # order, the preceding tags would become ``<TAGA/>1</TAGA>'' and
\r
1927 # ``<TAGB/>2</TAGB>''
\r
1928 $ zmodload zsh/mapfile
\r
1930 $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\
\r
1931 > (#im)<TAGA>*<\/TAGA>/<TAGA>$((++cnt))<\/TAGA>}
\r
1933 # removing all files in users Maildir/new that contain ``filename="gone.src''
\r
1934 $ zmodload zsh/{files,mapfile}
\r
1935 $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \
\r
1936 *filename=\"gone.scr\"* ]]'})
\r
1938 # Grep out the Title from a postscript file and append that value to the
\r
1939 # end of the filename
\r
1941 $ zmodload zsh/mapfile
\r
1942 $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'</code></pre>
\r
1945 <div class="sect3">
\r
1946 <h4 id="_zsh_mathfunc_require_zmodload_zsh_mathfunc">zsh/mathfunc (require zmodload zsh/mathfunc)</h4>
\r
1947 <div class="listingblock">
\r
1948 <div class="content">
\r
1949 <pre><code>$ zmodload zsh/mathfunc
\r
1950 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
\r
1951 -1.1102230246251565e-16
\r
1952 $ echo $(( pi = 4.0 * atan(1.0) ))
\r
1953 3.1415926535897931
\r
1954 $ echo $(( f = sin(0.3) ))
\r
1955 0.29552020666133955
\r
1956 $ print $((1e12 * rand48()))
\r
1957 847909677310.23413
\r
1958 $ print $(( rand48(seed) ))
\r
1959 0.01043488334700271</code></pre>
\r
1962 <div class="sect3">
\r
1963 <h4 id="_zsh_termcap_require_zmodload_zsh_termcap">zsh/termcap (require zmodload zsh/termcap)</h4>
\r
1964 <div class="listingblock">
\r
1965 <div class="content">
\r
1966 <pre><code> $ zmodload -ab zsh/termcap echotc
\r
1967 $ GREEN=`echotc AF 2`
\r
1968 $ YELLOW=`echotc AF 3`
\r
1969 $ RED=`echotc AF 1`
\r
1970 $ BRIGHTRED=`echotc md ; echotc AF 1`
\r
1971 $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred</code></pre>
\r
1974 <div class="sect3">
\r
1975 <h4 id="_zsh_zpty_require_zmodload_zsh_zpty">zsh/zpty (require zmodload zsh/zpty)</h4>
\r
1976 <div class="listingblock">
\r
1977 <div class="content">
\r
1978 <pre><code> $ zmodload zsh/zpty
\r
1979 $ zpty PW passwd $1
\r
1980 $ zpty PW passwd $1
\r
1981 # ``-r'': read the output of the command name.
\r
1982 # ``z'' : Parameter
\r
1983 $ zpty -r PW z '*password:'
\r
1984 # send the to command name the given strings as input
\r
1986 $ zpty -r PW z '*password:'
\r
1988 # The second form, with the -d option, is used to delete commands
\r
1989 # previously started, by supplying a list of their names. If no names
\r
1990 # are given, all commands are deleted. Deleting a command causes the HUP
\r
1991 # signal to be sent to the corresponding process.
\r
1992 $ zpty -d PW</code></pre>
\r
1995 <div class="sect3">
\r
1996 <h4 id="_zsh_net_socket_require_zmodload_zsh_net_socket">zsh/net/socket (require zmodload zsh/net/socket)</h4>
\r
1997 <div class="listingblock">
\r
1998 <div class="content">
\r
1999 <pre><code># ``-l'': open a socket listening on filename
\r
2000 # ``-d'': argument will be taken as the target file descriptor for the
\r
2002 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''
\r
2003 # (3.7.2: File descriptors)
\r
2004 $ zmodload zsh/net/socket
\r
2006 # ``-a'': accept an incoming connection to the socket
\r
2007 $ zsocket -a -d 4 3
\r
2008 $ zsocket -a -d 5 3 # accept a connection
\r
2009 $ echo foobar >&4
\r
2010 $ echo barfoo >&5
\r
2011 $ 4>&- 5>&- 3>&</code></pre>
\r
2014 <div class="sect3">
\r
2015 <h4 id="_zsh_zftp_require_zmodload_zsh_zftp">zsh/zftp (require zmodload zsh/zftp)</h4>
\r
2016 <div class="listingblock">
\r
2017 <div class="content">
\r
2018 <pre><code> $ autoload -U zfinit
\r
2020 $ zfparams www.example.invalid myuserid mypassword
\r
2023 $ zfls -l zshtips.html
\r
2024 $ zfput zshtips.html
\r
2025 $ zfls -l zshtips.html
\r
2027 # Automatically transfer files using FTP with error checking
\r
2028 $ autoload -U zfinit ; zfinit
\r
2029 $ zftp open host.name.invalid user passwd || exit
\r
2030 $ zftp get /remote/file > /local/file; r=$?
\r
2031 $ zftp close && exit r
\r
2033 # compress and ftp on the fly
\r
2034 $ autoload -U zfinit ; zfinit
\r
2035 $ zftp open host.name.invalid user password
\r
2036 $ zftp get $file | bzip2 > ${file}.bz2
\r
2039 # Recursice ``get''
\r
2040 $ autoload -U zfinit ; zfinit
\r
2042 $ zfcd daemontools
\r
2043 $ for file in `zfls` ; do
\r
2048 # Upload all regular files in $HOME/foobar (recursive) that are newer than
\r
2049 # two hours to ftp.foobar.invalid/path/to/upload
\r
2050 $ autoload -U zfinit ; zfinit
\r
2051 $ zfopen ftp.foobar.invalid/path/to/upload
\r
2053 $ zfput -r **/*(.mh-2)
\r
2056 # long list of files on a ftp
\r
2057 $ autoload -U zfinit ; zfinit
\r
2058 $ zfopen some-host
\r
2059 $ zfcd /some/remote/Dir
\r
2060 $ cd /some/local/Dir
\r
2061 # If the list.txt is located on the remote host, change to
\r
2062 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}
\r
2063 $ zfget ${(f)"$(cat list.txt)"}
\r
2064 $ zfclose</code></pre>
\r
2067 <div class="sect3">
\r
2068 <h4 id="_zsh_zselect_require_zmodload_zsh_zselect">zsh/zselect (require zmodload zsh/zselect)</h4>
\r
2069 <div class="listingblock">
\r
2070 <div class="content">
\r
2071 <pre><code># It's similar to
\r
2074 | $ stty -icanon min 0 time 50
\r
2077 | $ case "$yesno" in
\r
2078 | > yes) command1;;
\r
2079 | > *) command2;;
\r
2082 $ zmodload zsh/zselect
\r
2083 $ if zselect -t 500 -r 0 && read yesno && [ yes = "$yesno" ]; then
\r
2087 > fi</code></pre>
\r
2093 <div class="sect1">
\r
2094 <h2 id="_options">OPTIONS</h2>
\r
2095 <div class="sectionbody">
\r
2096 <div class="sect2">
\r
2097 <h3 id="_navigation_options">Navigation options</h3>
\r
2098 <div class="paragraph"><p><strong>auto_cd</strong> (allow one to change to a directory by entering it as a
\r
2099 command). <strong>auto_pushd</strong> (automatically append dirs to the push/pop list)
\r
2100 pushd_ignore_dups (and don’t duplicate them).</p></div>
\r
2102 <div class="sect2">
\r
2103 <h3 id="_misc">Misc</h3>
\r
2104 <div class="paragraph"><p><strong>no_hup</strong> (don’t send HUP signal to background jobs when exiting ZSH).
\r
2105 <strong>print_exit_value</strong> (show a message with the exit code when a command
\r
2106 returns with a non-zero exit code)</p></div>
\r
2107 <div class="sect3">
\r
2108 <h4 id="_history_options">History options</h4>
\r
2109 <div class="paragraph"><p><strong>hist_verify</strong> (let the user edit the command line after history
\r
2110 expansion (e.g. !ls) instead of immediately running it)<br />
\r
2111 Use the same history file for all sessions :<br />
\r
2112 <strong>setopt SHARE_HISTORY</strong></p></div>
\r
2114 <div class="sect3">
\r
2115 <h4 id="_privacy_security">Privacy / Security</h4>
\r
2116 <div class="paragraph"><p><strong>no_clobber</strong> (or set -C; prevent <em>></em> redirection from truncating
\r
2117 the given file if it already exists)</p></div>
\r
2119 <div class="sect3">
\r
2120 <h4 id="_spelling_correction">Spelling correction</h4>
\r
2121 <div class="paragraph"><p><strong>correct</strong> (automatically correct the spelling of commands).
\r
2122 <strong>correct_all</strong> (automatically correct the spelling of each word on the
\r
2123 command line) <strong>dvorak</strong> (dvorak layout)</p></div>
\r
2128 <div class="sect1">
\r
2129 <h2 id="_unsorted_misc">UNSORTED/MISC</h2>
\r
2130 <div class="sectionbody">
\r
2131 <div class="paragraph"><p>Mailpath: simple multiple mailpath:</p></div>
\r
2132 <div class="listingblock">
\r
2133 <div class="content">
\r
2134 <pre><code>mailpath=($HOME/Mail/mbox'?new mail in mbox'
\r
2135 $HOME/Mail/tux.u-strasbg'?new mail in tux'
\r
2136 $HOME/Mail/lilo'?new mail in lilo'
\r
2137 $HOME/Mail/ldap-fr'?new mail in ldap-fr')</code></pre>
\r
2139 <div class="paragraph"><p>Mailpath: dynamic mailpath:</p></div>
\r
2140 <div class="listingblock">
\r
2141 <div class="content">
\r
2142 <pre><code>typeset -a mailpath
\r
2143 for i in ~/Mail/Lists/*(.); do
\r
2144 mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."
\r
2147 <div class="paragraph"><p>Avoid globbing on special commands:</p></div>
\r
2148 <div class="listingblock">
\r
2149 <div class="content">
\r
2150 <pre><code>for com in alias expr find mattrib mcopy mdir mdel which;
\r
2151 alias $com="noglob $com"</code></pre>
\r
2153 <div class="paragraph"><p>For migrating your bashprompt to zsh use the script bash2zshprompt located in
\r
2154 the zsh source distribution under <em>Misc</em>.</p></div>
\r
2155 <div class="paragraph"><p>For migration from (t)csh to zsh use the c2z tool that converts csh
\r
2156 aliases and environment and shell variables to zsh. It does this by running
\r
2157 csh, and having csh report on aliases and variables. The script then converts
\r
2158 these to zsh startup files. It has some issues and usage information that are
\r
2159 documented at the top of this script.</p></div>
\r
2160 <div class="paragraph"><p>Here are functions to set the title and hardstatus of an <strong>XTerm</strong> or of <strong>GNU
\r
2161 Screen</strong> to <em>zsh</em> and the current directory, respectively, when the prompt is
\r
2162 displayed, and to the command name and rest of the command line, respectively,
\r
2163 when a command is executed:</p></div>
\r
2164 <div class="listingblock">
\r
2165 <div class="content">
\r
2166 <pre><code>function title {
\r
2167 if [[ $TERM == "screen" ]]; then
\r
2168 # Use these two for GNU Screen:
\r
2169 print -nR $' 33k'$1$' 33'\
\r
2170 print -nR $' 33]0;'$2$''
\r
2171 elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
\r
2172 # Use this one instead for XTerms:
\r
2173 print -nR $' 33]0;'$*$''
\r
2176 function precmd { title zsh "$PWD" }
\r
2177 function preexec {
\r
2179 local -a cmd; cmd=(${(z)1})
\r
2180 title $cmd[1]:t "$cmd[2,-1]"
\r
2183 <div class="paragraph"><p>Put the following line into your ~/.screenrc to see this fancy hardstatus:</p></div>
\r
2184 <div class="listingblock">
\r
2185 <div class="content">
\r
2186 <pre><code>caption always "%3n %t%? (%u)%?%?: %h%?"</code></pre>
\r
2188 <div class="paragraph"><p>Special variables which are assigned:</p></div>
\r
2189 <div class="listingblock">
\r
2190 <div class="content">
\r
2191 <pre><code>$LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID
\r
2192 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath</code></pre>
\r
2196 <div class="sect1">
\r
2197 <h2 id="_links">LINKS</h2>
\r
2198 <div class="sectionbody">
\r
2199 <div class="dlist"><dl>
\r
2200 <dt class="hdlist1">
\r
2205 <strong><a href="http://www.zsh.org/">http://www.zsh.org/</a></strong>
\r
2208 <dt class="hdlist1">
\r
2213 <strong><a href="https://zsh.sourceforge.io/">https://zsh.sourceforge.io/</a></strong>
\r
2216 <dt class="hdlist1">
\r
2221 <strong><a href="http://sourceforge.net/projects/zsh/">http://sourceforge.net/projects/zsh/</a></strong>
\r
2224 <dt class="hdlist1">
\r
2225 From Bash to Z Shell: Conquering the Command Line - the book
\r
2229 <strong><a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a></strong>
\r
2232 <dt class="hdlist1">
\r
2233 "Zsh - die magische Shell" (german book about Zsh) by Sven Guckes and Julius Plenz
\r
2237 <strong><a href="http://zshbuch.org/">http://zshbuch.org/</a></strong>
\r
2240 <dt class="hdlist1">
\r
2241 Mailinglistarchive
\r
2245 <strong><a href="http://www.zsh.org/mla/">http://www.zsh.org/mla/</a></strong>
\r
2248 <dt class="hdlist1">
\r
2253 <strong><a href="https://zsh.sourceforge.io/FAQ/zshfaq.html">https://zsh.sourceforge.io/FAQ/zshfaq.html</a></strong>
\r
2256 <dt class="hdlist1">
\r
2261 <strong><a href="https://zsh.sourceforge.io/Guide/">https://zsh.sourceforge.io/Guide/</a></strong>
\r
2264 <dt class="hdlist1">
\r
2269 <strong><a href="http://zshwiki.org/home/">http://zshwiki.org/home/</a></strong>
\r
2272 <dt class="hdlist1">
\r
2277 <strong><a href="http://stchaz.free.fr/mouse.zsh">http://stchaz.free.fr/mouse.zsh</a></strong>
\r
2280 <dt class="hdlist1">
\r
2281 ZSH Prompt introduction
\r
2285 <strong><a href="http://aperiodic.net/phil/prompt/">http://aperiodic.net/phil/prompt/</a></strong>
\r
2288 <dt class="hdlist1">
\r
2289 ft’s zsh configuration
\r
2293 <strong><a href="http://ft.bewatermyfriend.org/computer/zsh.html">http://ft.bewatermyfriend.org/computer/zsh.html</a></strong>
\r
2296 <dt class="hdlist1">
\r
2297 Adam’s ZSH page
\r
2301 <strong><a href="http://www.adamspiers.org/computing/zsh/">http://www.adamspiers.org/computing/zsh/</a></strong>
\r
2304 <dt class="hdlist1">
\r
2305 Zzappers Best of ZSH Tips
\r
2309 <strong><a href="http://www.rayninfo.co.uk/tips/zshtips.html">http://www.rayninfo.co.uk/tips/zshtips.html</a></strong>
\r
2312 <dt class="hdlist1">
\r
2313 Zsh Webpage by Christian Schneider
\r
2317 <strong><a href="http://www.strcat.de/zsh/">http://www.strcat.de/zsh/</a></strong>
\r
2320 <dt class="hdlist1">
\r
2321 The zsh-lovers webpage
\r
2325 <strong><a href="http://grml.org/zsh/">http://grml.org/zsh/</a></strong>
\r
2328 <dt class="hdlist1">
\r
2333 <strong>#zsh at irc.freenode.org</strong>
\r
2336 <dt class="hdlist1">
\r
2337 The Z shell reference-card (included in the zsh-lovers debian-package)
\r
2341 <strong><a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a></strong>
\r
2347 <div class="sect1">
\r
2348 <h2 id="_authors">AUTHORS</h2>
\r
2349 <div class="sectionbody">
\r
2350 <div class="paragraph"><p>This manpage was written by Michael Prokop, Christian <em>strcat</em>
\r
2351 Schneider and Matthias Kopfermann. But many ideas have been taken from
\r
2352 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),
\r
2353 google, newsgroups and the zsh-Wiki.<br />
\r
2354 Thanks for your cool and incredible tips. We learned much from you!</p></div>
\r
2355 <div class="paragraph"><p>In alphabetic order:</p></div>
\r
2356 <div class="listingblock">
\r
2357 <div class="content">
\r
2358 <pre><code>Andrew 'zefram' Main - http://www.fysh.org/~zefram/
\r
2359 Barton E. Schaefer - http://www.well.com/user/barts/
\r
2360 Matthias Kopfermann - http://www.guckes.net/zsh/lover.html
\r
2361 Oliver Kiddle - http://people.freenet.de/opk/
\r
2362 Paul Falstad - http://www.falstad.com/
\r
2363 Peter Stephenson - http://homepage.ntlworld.com/p.w.stephenson/
\r
2365 Stephane Chazelas - http://stephane.chazelas.free.fr/
\r
2366 Sven Guckes - http://www.guckes.net/
\r
2367 Sven Wischnowsky - http://w9y.de/</code></pre>
\r
2371 <div class="sect1">
\r
2372 <h2 id="_see_also">SEE ALSO</h2>
\r
2373 <div class="sectionbody">
\r
2374 <div class="paragraph"><p>Manpages of zsh:</p></div>
\r
2375 <div class="listingblock">
\r
2376 <div class="content">
\r
2377 <pre><code> zsh Zsh overview
\r
2378 zshall Tthe Z shell meta-man page
\r
2379 zshbuiltins Zsh built-in commands
\r
2380 zshcalsys zsh calendar system
\r
2381 zshcompctl zsh programmable completion
\r
2382 zshcompsys Zsh completion system
\r
2383 zshcompwid Zsh completion widgets
\r
2384 zshcontrib User contributions to zsh
\r
2385 zshexpn Zsh expansion and substitution
\r
2386 zshmisc Anything not fitting into the other sections
\r
2387 zshmodules Zsh loadable modules
\r
2388 zshoptions Zsh options
\r
2389 zshparam Zsh parameters
\r
2390 zshroadmap Informal introduction to the zsh manual
\r
2391 zshtcpsys Zsh tcp system
\r
2392 zshzle Zsh command line editing
\r
2393 zshzftpsys Zsh built-in FTP client
\r
2394 zshall Meta-man page containing all of the above</code></pre>
\r
2396 <div class="paragraph"><p>Note: especially <em>man zshcontrib</em> covers very useful topics!<br />
\r
2397 Book: <strong>From Bash to Z Shell</strong> by Oliver Kiddle, Jerry Peck and Peter
\r
2398 Stephenson. <strong>ISBN: 1590593766</strong>. - <strong><a href="http://www.bash2zsh.com/">bash2zsh.com</a></strong><br />
\r
2399 Also take a look at the section <strong>LINKS</strong> in this manpage.</p></div>
\r
2402 <div class="sect1">
\r
2403 <h2 id="_bugs">BUGS</h2>
\r
2404 <div class="sectionbody">
\r
2405 <div class="paragraph"><p>Probably. This manpage might be never complete.
\r
2406 So please report bugs, feedback and suggestions via <a href="https://github.com/grml/zsh-lovers">https://github.com/grml/zsh-lovers</a>
\r
2407 Thank you!</p></div>
\r
2410 <div class="sect1">
\r
2411 <h2 id="_copyright">COPYRIGHT</h2>
\r
2412 <div class="sectionbody">
\r
2413 <div class="paragraph"><p>Copyright (C) Michael Prokop, Christian Schneider and Matthias
\r
2414 Kopfermann.</p></div>
\r
2418 <div id="footnotes"><hr /></div>
\r
2420 <div id="footer-text">
\r
2422 2023-09-08 11:52:40 UTC
\r