Clarify that we no longer support i586 but require i686+
[grml.org.git] / online-docs / zsh-lovers.1.html
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
4 <head>\r
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
6 <meta name="generator" content="AsciiDoc 8.2.2" />\r
7 <style type="text/css">\r
8 /* Debug borders */\r
9 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {\r
10 /*\r
11   border: 1px solid red;\r
12 */\r
13 }\r
14 \r
15 body {\r
16   margin: 1em 5% 1em 5%;\r
17 }\r
18 \r
19 a {\r
20   color: blue;\r
21   text-decoration: underline;\r
22 }\r
23 a:visited {\r
24   color: fuchsia;\r
25 }\r
26 \r
27 em {\r
28   font-style: italic;\r
29 }\r
30 \r
31 strong {\r
32   font-weight: bold;\r
33 }\r
34 \r
35 tt {\r
36   color: navy;\r
37 }\r
38 \r
39 h1, h2, h3, h4, h5, h6 {\r
40   color: #527bbd;\r
41   font-family: sans-serif;\r
42   margin-top: 1.2em;\r
43   margin-bottom: 0.5em;\r
44   line-height: 1.3;\r
45 }\r
46 \r
47 h1 {\r
48   border-bottom: 2px solid silver;\r
49 }\r
50 h2 {\r
51   border-bottom: 2px solid silver;\r
52   padding-top: 0.5em;\r
53 }\r
54 \r
55 div.sectionbody {\r
56   font-family: serif;\r
57   margin-left: 0;\r
58 }\r
59 \r
60 hr {\r
61   border: 1px solid silver;\r
62 }\r
63 \r
64 p {\r
65   margin-top: 0.5em;\r
66   margin-bottom: 0.5em;\r
67 }\r
68 \r
69 pre {\r
70   padding: 0;\r
71   margin: 0;\r
72 }\r
73 \r
74 span#author {\r
75   color: #527bbd;\r
76   font-family: sans-serif;\r
77   font-weight: bold;\r
78   font-size: 1.1em;\r
79 }\r
80 span#email {\r
81 }\r
82 span#revision {\r
83   font-family: sans-serif;\r
84 }\r
85 \r
86 div#footer {\r
87   font-family: sans-serif;\r
88   font-size: small;\r
89   border-top: 2px solid silver;\r
90   padding-top: 0.5em;\r
91   margin-top: 4.0em;\r
92 }\r
93 div#footer-text {\r
94   float: left;\r
95   padding-bottom: 0.5em;\r
96 }\r
97 div#footer-badges {\r
98   float: right;\r
99   padding-bottom: 0.5em;\r
100 }\r
101 \r
102 div#preamble,\r
103 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,\r
104 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,\r
105 div.admonitionblock {\r
106   margin-right: 10%;\r
107   margin-top: 1.5em;\r
108   margin-bottom: 1.5em;\r
109 }\r
110 div.admonitionblock {\r
111   margin-top: 2.5em;\r
112   margin-bottom: 2.5em;\r
113 }\r
114 \r
115 div.content { /* Block element content. */\r
116   padding: 0;\r
117 }\r
118 \r
119 /* Block element titles. */\r
120 div.title, caption.title {\r
121   font-family: sans-serif;\r
122   font-weight: bold;\r
123   text-align: left;\r
124   margin-top: 1.0em;\r
125   margin-bottom: 0.5em;\r
126 }\r
127 div.title + * {\r
128   margin-top: 0;\r
129 }\r
130 \r
131 td div.title:first-child {\r
132   margin-top: 0.0em;\r
133 }\r
134 div.content div.title:first-child {\r
135   margin-top: 0.0em;\r
136 }\r
137 div.content + div.title {\r
138   margin-top: 0.0em;\r
139 }\r
140 \r
141 div.sidebarblock > div.content {\r
142   background: #ffffee;\r
143   border: 1px solid silver;\r
144   padding: 0.5em;\r
145 }\r
146 \r
147 div.listingblock {\r
148   margin-right: 0%;\r
149 }\r
150 div.listingblock > div.content {\r
151   border: 1px solid silver;\r
152   background: #f4f4f4;\r
153   padding: 0.5em;\r
154 }\r
155 \r
156 div.quoteblock > div.content {\r
157   padding-left: 2.0em;\r
158 }\r
159 \r
160 div.attribution {\r
161   text-align: right;\r
162 }\r
163 div.verseblock + div.attribution {\r
164   text-align: left;\r
165 }\r
166 \r
167 div.admonitionblock .icon {\r
168   vertical-align: top;\r
169   font-size: 1.1em;\r
170   font-weight: bold;\r
171   text-decoration: underline;\r
172   color: #527bbd;\r
173   padding-right: 0.5em;\r
174 }\r
175 div.admonitionblock td.content {\r
176   padding-left: 0.5em;\r
177   border-left: 2px solid silver;\r
178 }\r
179 \r
180 div.exampleblock > div.content {\r
181   border-left: 2px solid silver;\r
182   padding: 0.5em;\r
183 }\r
184 \r
185 div.verseblock div.content {\r
186   white-space: pre;\r
187 }\r
188 \r
189 div.imageblock div.content { padding-left: 0; }\r
190 div.imageblock img { border: 1px solid silver; }\r
191 span.image img { border-style: none; }\r
192 \r
193 dl {\r
194   margin-top: 0.8em;\r
195   margin-bottom: 0.8em;\r
196 }\r
197 dt {\r
198   margin-top: 0.5em;\r
199   margin-bottom: 0;\r
200   font-style: italic;\r
201 }\r
202 dd > *:first-child {\r
203   margin-top: 0;\r
204 }\r
205 \r
206 ul, ol {\r
207     list-style-position: outside;\r
208 }\r
209 ol.olist2 {\r
210   list-style-type: lower-alpha;\r
211 }\r
212 \r
213 div.tableblock > table {\r
214   border: 3px solid #527bbd;\r
215 }\r
216 thead {\r
217   font-family: sans-serif;\r
218   font-weight: bold;\r
219 }\r
220 tfoot {\r
221   font-weight: bold;\r
222 }\r
223 \r
224 div.hlist {\r
225   margin-top: 0.8em;\r
226   margin-bottom: 0.8em;\r
227 }\r
228 div.hlist td {\r
229   padding-bottom: 5px;\r
230 }\r
231 td.hlist1 {\r
232   vertical-align: top;\r
233   font-style: italic;\r
234   padding-right: 0.8em;\r
235 }\r
236 td.hlist2 {\r
237   vertical-align: top;\r
238 }\r
239 \r
240 @media print {\r
241   div#footer-badges { display: none; }\r
242 }\r
243 \r
244 div#toctitle {\r
245   color: #527bbd;\r
246   font-family: sans-serif;\r
247   font-size: 1.1em;\r
248   font-weight: bold;\r
249   margin-top: 1.0em;\r
250   margin-bottom: 0.1em;\r
251 }\r
252 \r
253 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {\r
254   margin-top: 0;\r
255   margin-bottom: 0;\r
256 }\r
257 div.toclevel2 {\r
258   margin-left: 2em;\r
259   font-size: 0.9em;\r
260 }\r
261 div.toclevel3 {\r
262   margin-left: 4em;\r
263   font-size: 0.9em;\r
264 }\r
265 div.toclevel4 {\r
266   margin-left: 6em;\r
267   font-size: 0.9em;\r
268 }\r
269 /* Workarounds for IE6's broken and incomplete CSS2. */\r
270 \r
271 div.sidebar-content {\r
272   background: #ffffee;\r
273   border: 1px solid silver;\r
274   padding: 0.5em;\r
275 }\r
276 div.sidebar-title, div.image-title {\r
277   font-family: sans-serif;\r
278   font-weight: bold;\r
279   margin-top: 0.0em;\r
280   margin-bottom: 0.5em;\r
281 }\r
282 \r
283 div.listingblock div.content {\r
284   border: 1px solid silver;\r
285   background: #f4f4f4;\r
286   padding: 0.5em;\r
287 }\r
288 \r
289 div.quoteblock-content {\r
290   padding-left: 2.0em;\r
291 }\r
292 \r
293 div.exampleblock-content {\r
294   border-left: 2px solid silver;\r
295   padding-left: 0.5em;\r
296 }\r
297 \r
298 /* IE6 sets dynamically generated links as visited. */\r
299 div#toc a:visited { color: blue; }\r
300 </style>\r
301 <title>ZSH-LOVERS(1)</title>\r
302 </head>\r
303 <body>\r
304 <div id="header">\r
305 <h1>ZSH-LOVERS(1)</h1>\r
306 </div>\r
307 <h2>NAME</h2>\r
308 <div class="sectionbody">\r
309 <p>zsh-lovers - tips, tricks and examples for the Z shell</p>\r
310 </div>\r
311 <h2>SYNOPSIS</h2>\r
312 <div class="sectionbody">\r
313 <p>Just read it. ;-)</p>\r
314 </div>\r
315 <h2>OVERVIEW</h2>\r
316 <div class="sectionbody">\r
317 <p>Whenever we look at the zsh manual we wonder why there are no examples or those\r
318 simply things in (shell) life.  The zsh contains many features, but there was no\r
319 manpage with some examples (like procmailex(5)).  That's why we wrote this\r
320 manpage.</p>\r
321 <p>Most of the tricks and oneliner come from the mailinglists zsh-users,\r
322 zsh-workers, google, newsgroups and from ourself.  See section <strong>LINKS</strong> for\r
323 details.</p>\r
324 <p>Note: This manpage (zsh-lovers(1)) is <strong>not</strong> an offical part of the Z shell! It's\r
325 just a just for fun - manpage ;)<br />\r
326 For comments, bugreports and feedback take a quick look at the section <strong>BUGS</strong>.</p>\r
327 </div>\r
328 <h2>SHELL-SCRIPTING</h2>\r
329 <div class="sectionbody">\r
330 <p>This section provides some examples for often needed shellscript-stuff. Notice\r
331 that you should not use otherwise most examples won't work.<br />\r
332 Parse options in shellscripts. Example taken from ZWS by Adam Chodorowski\r
333 (<a href="http://www.chodorowski.com/projects/zws/">http://www.chodorowski.com/projects/zws/</a>):</p>\r
334 <div class="listingblock">\r
335 <div class="content">\r
336 <pre><tt>parse_options()\r
337 {\r
338     o_port=(-p 9999)\r
339     o_root=(-r WWW)\r
340     o_log=(-d ZWS.log)\r
341 \r
342     zparseopts -K -- p:=o_port r:=o_root l:=o_log h=o_help\r
343     if [[ $? != 0 || "$o_help" != "" ]]; then\r
344         echo Usage: $(basename "$0") "[-p PORT] [-r DIRECTORY]"\r
345         exit 1\r
346     fi\r
347 \r
348     port=$o_port[2]\r
349     root=$o_root[2]\r
350     log=$o_log[2]\r
351 \r
352     if [[ $root[1] != '/' ]]; then root="$PWD/$root"; fi\r
353 }\r
354 # now use the function:\r
355 parse_options $*</tt></pre>\r
356 </div></div>\r
357 </div>\r
358 <h2>EXAMPLES</h2>\r
359 <div class="sectionbody">\r
360 <p>Available subsections are <strong>Aliases</strong>, <strong>Completion</strong>, <strong>Unsorted/Misc examples</strong>,\r
361 <strong>(Recursive) Globbing - Examples</strong>, <strong>Modifiers usage</strong>, <strong>Redirection-Examples</strong>,\r
362 <strong>ZMV-Examples</strong> and <strong>Module-Examples</strong>.</p>\r
363 <h3>ALIASES</h3>\r
364 <p>Suffix aliases are supported in zsh since version 4.2.0. Some examples:</p>\r
365 <div class="listingblock">\r
366 <div class="content">\r
367 <pre><tt>alias -s tex=vim\r
368 alias -s html=w3m\r
369 alias -s org=w3m</tt></pre>\r
370 </div></div>\r
371 <p>Now pressing return-key after entering <em>foobar.tex</em> starts vim with\r
372 foobar.tex. Calling a html-file runs browser w3m. <em>www.zsh.org</em> and pressing\r
373 enter starts w3m with argument www.zsh.org.<br />\r
374 Global aliases can be used anywhere in the command line. Example:</p>\r
375 <div class="listingblock">\r
376 <div class="content">\r
377 <pre><tt>$ alias -g C='| wc -l'\r
378 $ grep alias ~/.zsh/* C\r
379 443</tt></pre>\r
380 </div></div>\r
381 <p>Some more or less useful global aliases (choose whether they are useful  or not\r
382 for you on your own):</p>\r
383 <div class="listingblock">\r
384 <div class="content">\r
385 <pre><tt>alias -g ...='../..'\r
386 alias -g ....='../../..'\r
387 alias -g .....='../../../..'\r
388 alias -g CA="2&gt;&amp;1 | cat -A"\r
389 alias -g C='| wc -l'\r
390 alias -g D="DISPLAY=:0.0"\r
391 alias -g DN=/dev/null\r
392 alias -g ED="export DISPLAY=:0.0"\r
393 alias -g EG='|&amp; egrep'\r
394 alias -g EH='|&amp; head'\r
395 alias -g EL='|&amp; less'\r
396 alias -g ELS='|&amp; less -S'\r
397 alias -g ETL='|&amp; tail -20'\r
398 alias -g ET='|&amp; tail'\r
399 alias -g F=' | fmt -'\r
400 alias -g G='| egrep'\r
401 alias -g H='| head'\r
402 alias -g HL='|&amp; head -20'\r
403 alias -g Sk="*~(*.bz2|*.gz|*.tgz|*.zip|*.z)"\r
404 alias -g LL="2&gt;&amp;1 | less"\r
405 alias -g L="| less"\r
406 alias -g LS='| less -S'\r
407 alias -g MM='| most'\r
408 alias -g M='| more'\r
409 alias -g NE="2&gt; /dev/null"\r
410 alias -g NS='| sort -n'\r
411 alias -g NUL="&gt; /dev/null 2&gt;&amp;1"\r
412 alias -g PIPE='|'\r
413 alias -g R=' &gt; /c/aaa/tee.txt '\r
414 alias -g RNS='| sort -nr'\r
415 alias -g S='| sort'\r
416 alias -g TL='| tail -20'\r
417 alias -g T='| tail'\r
418 alias -g US='| sort -u'\r
419 alias -g VM=/var/log/messages\r
420 alias -g X0G='| xargs -0 egrep'\r
421 alias -g X0='| xargs -0'\r
422 alias -g XG='| xargs egrep'\r
423 alias -g X='| xargs'</tt></pre>\r
424 </div></div>\r
425 <h3>COMPLETION</h3>\r
426 <p>See also man 1 zshcompctl zshcompsys zshcompwid. zshcompctl is the old\r
427 style of zsh programmable completion, zshcompsys is the new completion\r
428 system, zshcompwid are the zsh completion widgets.</p>\r
429 <p>Some functions, like _apt and _dpkg, are very slow. You can use a cache\r
430 in order to proxy the list of  results  (like  the  list  of  available\r
431 debian packages) Use a cache:</p>\r
432 <div class="listingblock">\r
433 <div class="content">\r
434 <pre><tt>zstyle ':completion:*' use-cache on\r
435 zstyle ':completion:*' cache-path ~/.zsh/cache</tt></pre>\r
436 </div></div>\r
437 <p>Prevent CVS files/directories from being completed:</p>\r
438 <div class="listingblock">\r
439 <div class="content">\r
440 <pre><tt>zstyle ':completion:*:(all-|)files' ignored-patterns '(|*/)CVS'\r
441 zstyle ':completion:*:cd:*' ignored-patterns '(*/)#CVS'</tt></pre>\r
442 </div></div>\r
443 <p>Fuzzy matching of completions for when you mistype them:</p>\r
444 <div class="listingblock">\r
445 <div class="content">\r
446 <pre><tt>zstyle ':completion:*' completer _complete _match _approximate\r
447 zstyle ':completion:*:match:*' original only\r
448 zstyle ':completion:*:approximate:*' max-errors 1 numeric</tt></pre>\r
449 </div></div>\r
450 <p>And  if  you  want  the  number  of  errors  allowed by _approximate to\r
451 increase with the length of what you have typed so far:</p>\r
452 <div class="listingblock">\r
453 <div class="content">\r
454 <pre><tt>zstyle -e ':completion:*:approximate:*' \\r
455         max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'</tt></pre>\r
456 </div></div>\r
457 <p>Ignore completion functions for commands you don't have:</p>\r
458 <div class="listingblock">\r
459 <div class="content">\r
460 <pre><tt>zstyle ':completion:*:functions' ignored-patterns '_*'</tt></pre>\r
461 </div></div>\r
462 <p>With helper functions like:</p>\r
463 <div class="listingblock">\r
464 <div class="content">\r
465 <pre><tt>xdvi() { command xdvi ${*:-*.dvi(om[1])} }</tt></pre>\r
466 </div></div>\r
467 <p>you can avoid having to complete at all in many cases, but if  you  do,\r
468 you  might want to fall into menu selection immediately and to have the\r
469 words sorted by time:</p>\r
470 <div class="listingblock">\r
471 <div class="content">\r
472 <pre><tt>zstyle ':completion:*:*:xdvi:*' menu yes select\r
473 zstyle ':completion:*:*:xdvi:*' file-sort time</tt></pre>\r
474 </div></div>\r
475 <p>Completing process IDs with menu selection:</p>\r
476 <div class="listingblock">\r
477 <div class="content">\r
478 <pre><tt>zstyle ':completion:*:*:kill:*' menu yes select\r
479 zstyle ':completion:*:kill:*'   force-list always</tt></pre>\r
480 </div></div>\r
481 <p>If you end up using a directory  as  argument,  this  will  remove  the\r
482 trailing slash (usefull in ln)</p>\r
483 <div class="listingblock">\r
484 <div class="content">\r
485 <pre><tt>zstyle ':completion:*' squeeze-slashes true</tt></pre>\r
486 </div></div>\r
487 <p>cd will never select the parent directory (e.g.: cd ../&lt;TAB&gt;):</p>\r
488 <div class="listingblock">\r
489 <div class="content">\r
490 <pre><tt>zstyle ':completion:*:cd:*' ignore-parents parent pwd</tt></pre>\r
491 </div></div>\r
492 <p>Another method for <em>quick change directories</em>. Add this to your ~/.zshrc, then just enter\r
493 &#8220;cd &#8230;./dir&#8221;</p>\r
494 <div class="listingblock">\r
495 <div class="content">\r
496 <pre><tt>rationalise-dot() {\r
497   if [[ $LBUFFER = *.. ]]; then\r
498     LBUFFER+=/..\r
499   else\r
500     LBUFFER+=.\r
501   fi\r
502 }\r
503 zle -N rationalise-dot\r
504 bindkey . rationalise-dot</tt></pre>\r
505 </div></div>\r
506 <h3>UNSORTED/MISC examples</h3>\r
507 <p>Hint: A list of valid glob Qualifiers can be found in zshexpn(1).\r
508 See &#8220;man 1 zshexpn | less -p&#8221; Qualifiers for details.</p>\r
509 <div class="listingblock">\r
510 <div class="content">\r
511 <pre><tt># random numbers\r
512   $ echo $[${RANDOM}%1000]     # random between 0-999\r
513   $ echo $[${RANDOM}%11+10]    # random between 10-20\r
514   $ echo ${(l:3::0:)${RANDOM}} # N digits long (3 digits)\r
515 \r
516 # reverse a word\r
517   $ echo "${(j::)${(@Oa)${(s::):-hello}}}"\r
518 \r
519 # Show newest directory\r
520   $ ls -ld *(/om[1])\r
521 \r
522 # random array element\r
523   $ FILES=( .../files/* )\r
524   $ feh $FILES[$RANDOM%$#FILES+1]\r
525 \r
526 # cat first line in all files in this dir\r
527   $ for file (*(ND-.)) IFS= read -re &lt; $file\r
528 \r
529 # test if a parameter is numeric\r
530   $ if [[ $1 == &lt;-&gt; ]] ; then\r
531          echo numeric\r
532     else\r
533          echo non-numeric\r
534     fi\r
535 \r
536 # Show me all the .c files for which there doesn't exist a .o file.\r
537   $ print *.c(e_'[[ ! -e $REPLY:r.o ]]'_)\r
538 \r
539 # All files in /var/ that are not owned by root\r
540   $ ls -ld /var/*(^u:root)\r
541 \r
542 # All files for which the owner hat read and execute permissions\r
543   $ echo *(f:u+rx:)\r
544 \r
545 # The same, but also others dont have execute permissions\r
546   $ echo *(f:u+rx,o-x:)\r
547 \r
548 # brace expansion - example\r
549   $ X=(A B C)\r
550   $ Y=(+ -)\r
551   $ print -r -- $^X.$^Y\r
552   A.+ A.- B.+ B.- C.+ C.-\r
553 \r
554 # Fetch the newest file containing the string 'fgractg*.log' in the\r
555 # filename and contains the string 'ORA-' in it\r
556   $ file=(fgractg*.log(Nm0om[1]))\r
557   $ (($#file)) &amp;&amp; grep -l ORA- $file\r
558   # without Zsh\r
559   $ files=$( find . -name . -o -prune -name 'fgractg*&gt;log' -mtime 0 -print )\r
560   &gt; if [ -n "$files" ]; then\r
561   &gt;    IFS='\r
562   &gt; '\r
563   &gt; set -f\r
564   &gt; file=$(ls -td $files | head -1)\r
565   &gt; grep -l ORA- "$file"\r
566   &gt; fi\r
567 \r
568 # keep specified number of child processes running until entire task finished\r
569   $ zsh -c 'sleep 1 &amp; sleep 3 &amp; sleep 2&amp; print -rl -- $jobtexts'\r
570 \r
571 # Remove zero length and .bak files in a directory\r
572   $ rm -i *(.L0) *.bak(.)\r
573 \r
574 # print out files that dont have extensions\r
575   $ printf '%s\n' ^?*.*\r
576   $ printf '%s\n' ^?*.[^.]*(D)\r
577   $ ls -d -- ^?*.*(D)\r
578 \r
579 # Finding files which does not contain a specific string\r
580   $ print -rl file* | comm -2 -3 - &lt;(grep -l string file*)'\r
581   $ for f (file*(N)) grep -q string $f || print -r $f'\r
582 \r
583 # Show/Check whether a option is set or not. It works both with $options as\r
584 # with $builtins\r
585   $ echo $options[correct]\r
586   off\r
587   $ $options[zle]\r
588   on\r
589 \r
590 # Count the number of directories on the stack\r
591   $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or\r
592   $ dirs -v | awk '{n=$1}END{print n+1}'\r
593 \r
594 # Matching all files which do not have a dot in filename\r
595   $ ls *~*.*(.)\r
596 \r
597 # Show only the ip-address from ``ifconfig device''\r
598   # ifconfig from net-tools (Linux)\r
599   $ print ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://}\r
600   # ifconfig from 4.2BSD {Free,Net,Open}BSD\r
601   $ print ${$(/sbin/ifconfig tun0)[6]}\r
602 \r
603 # Ping all the IP addresses in a couple of class C's or all hosts\r
604 # into /etc/hosts\r
605   $ for i in {1..254}; do ping -c 1 192.168.13.$i; done\r
606   or\r
607   $ I=1\r
608   $ while ( [[ $I -le 255 ]] ) ; do ping -1 2 150.150.150.$I; let I++; done\r
609   or\r
610   $ for i in $(sed 's/#.*//' &gt; /etc/hosts | awk '{print $2}')\r
611   : do\r
612   :    echo "Trying $i ... "\r
613   :    ping -c 1 $i ;\r
614   :    echo '============================='\r
615   : done\r
616 \r
617 # load all available modules at startup\r
618   $ typeset -U m\r
619   $ m=()\r
620   $ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))\r
621   $ zmodload -i $m\r
622 \r
623 # Rename all files within a directory such that their names get a numeral\r
624 # prefix in the default sort order.\r
625   $ i=1; for j in *; do mv $j $i.$j; ((i++)); done\r
626   $ i=1; for f in *; do mv $f $(echo $i | \\r
627     awk '{ printf("%03d", $0)}').$f; ((i++)); done\r
628   $ integer i=0; for f in *; do mv $f $[i+=1].$f; done\r
629 \r
630 # Find (and print) all symbolic links without a target within the current\r
631 # dirtree.\r
632   $ $ file **/*(D@) | fgrep broken\r
633   $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i\r
634   $ echo **/*(@-^./=%p)\r
635   $ print -l **/*(-@)\r
636 \r
637 # List all plain files that do not have extensions listed in `fignore'\r
638   $ ls **/*~*(${~${(j/|/)fignore}})(.)\r
639   # see above, but now omit executables\r
640   $ ls **/*~*(${~${(j/|/)fignore}})(.^*)\r
641 \r
642 # Print out files that dont have extensions (require *setopt extendedglob*\r
643 # and *setopt dotglob*)\r
644   $ printf '%s\n' ^?*.*\r
645 \r
646 # List files in reverse order sorted by name\r
647   $ print -rl -- *(On)\r
648   or\r
649   $ print -rl -- *(^on)\r
650 \r
651 # Synonymic to ``ps ax | awk '{print $1}'''\r
652   $ print -l /proc/*/cwd(:h:t:s/self//)\r
653 \r
654 # Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..\r
655 # (under Linux)\r
656   $ pid2 () {\r
657   &gt;   local i\r
658   &gt;   for i in /proc/&lt;-&gt;/stat\r
659   &gt; do\r
660   &gt;   [[ "$(&lt; $i)" = *\((${(j:|:)~@})\)* ]] &amp;&amp; echo $i:h:t\r
661   &gt; done\r
662   &gt; }\r
663 \r
664 # for X in 'n' 'o' 'p' 'q' 'r' 's' 't' 'u' 'v' 'w' 'x' 'y'; do ...\r
665   $ for (( i = 36#n; i &lt;= 36#y; i++ )); do\r
666   &gt;   print ${$(([##36]i)):l}\r
667   &gt; done\r
668 # or in combination with ``dc''\r
669   $ print {$((##n))..$((##y))}P\ 10P | dc\r
670 # or with ``eval''\r
671   $ eval print '${$(([##36]'{$((36#n))..$((36#y))}')):l}'\r
672 \r
673 # foreach in one line of shell\r
674   $ for f (*) print -r -- $f\r
675 \r
676 # copy a directory recursively without data/files\r
677   $ dirs=(**/*(/))\r
678   $ cd -- $dest_root\r
679   $ mkdir -p -- $dirs\r
680 # or without zsh\r
681   $ find . -type d -exec env d="$dest_root" \\r
682     sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;\r
683 \r
684 # If `foo=23'', then print with 10 digit with leading '0'.\r
685   $ foo=23\r
686   $ print ${(r:10::0:)foo}\r
687 \r
688 # find the name of all the files in their home directory that have\r
689 # more than 20 characters in their file names\r
690   print -rl $HOME/${(l:20::?:)~:-}*\r
691 \r
692 # Save arrays\r
693   $ print -r -- ${(qq)m} &gt; $nameoffile      # save it\r
694   $ eval "m=($(cat -- $nameoffile)"            # or use\r
695   $ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it\r
696 \r
697 # get a "ls -l" on all the files in the tree that are younger than a\r
698 # specified age (e.g "ls -l" all the files in the tree that where\r
699 # modified in the last 2 days)\r
700   $ ls -tld **/*(m-2)\r
701 # This will give you a listing 1 file perl line (not Ã  la ls -R).\r
702 # Think of an easy way to have a "ls -R" style output with\r
703 # only files newer than 2 day old.\r
704   $ for d (. ./**/*(/)) {\r
705   &gt;   print -r -- $'\n'${d}:\r
706   &gt;   cd $d &amp;&amp; {\r
707   &gt;       l=(*(Nm-2))\r
708   &gt;       (($#l)) &amp;&amp; ls -ltd -- $l\r
709   &gt;       cd ~-\r
710   &gt;   }\r
711   &gt; }\r
712 # If you also want directories to be included even if their mtime\r
713 # is more than 2 days old:\r
714   $ for d (. ./**/*(/)) {\r
715   &gt;   print -r -- $'\n'${d}:\r
716   &gt;   cd $d &amp;&amp; {\r
717   &gt;      l=(*(N/,m-2))\r
718   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l\r
719   &gt;      cd ~-\r
720   &gt;   }\r
721   &gt; }\r
722 # And if you want only the directories with mtime &lt; 2 days to be listed:\r
723   $ for d (. ./**/*(N/m-2)) {\r
724   &gt;   print -r -- $'\n'${d}:\r
725   &gt;   cd $d &amp;&amp; {\r
726   &gt;      l=(*(Nm-2))\r
727   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l\r
728   &gt;      cd ~-\r
729   &gt;   }\r
730   &gt; }\r
731 \r
732 # print 42 ``-''\r
733   $ echo ${(l:42::-:)}\r
734 # or use ``$COLUMS''\r
735   $ echo ${(l:$COLUMNS::-:)}\r
736 # and now with colors (require autoload colors ;colors)\r
737   $ echo "$bg[red]$fg[black]${(l:42::-:)}"\r
738 \r
739 # Redirect STDERR to a command like xless without redirecting STDOUT as well.\r
740   $ foo 2&gt;&gt;(xless)\r
741 # but this executes the command asynchronously. To do it synchronously:\r
742   $ { { foo 1&gt;&amp;3 } 2&gt;&amp;1 | xless } 3&gt;&amp;1\r
743 \r
744 # Rename all MP3-Files from name with spaces.mp3 to Name With Spaces.mp3\r
745   $ for i in *.mp3; do\r
746   &gt;     mv $i ${${(C)i}:s/Mp3/mp3/}\r
747   &gt; done\r
748 \r
749 # Match file names containing only digits and ending with .xml (require\r
750 # *setopt kshglob*)\r
751   $ ls -l [0-9]##.xml\r
752   $ ls -l &lt;0-&gt;.xml\r
753 \r
754 # Remove all "non txt" files\r
755   $ rm ./^*.txt\r
756 \r
757 # Move 200 files from a directory into another\r
758   $ mv -- *([1,200]) /another/Dir\r
759 \r
760 # Convert images (foo.gif =&gt; foo.png):\r
761   $ for i in **/*.gif; convert $i $i:r.png\r
762 \r
763 # convert a collection of mp3 files to wave or cdr,\r
764 # e.g. file.wav -&gt; file.mp3)\r
765   $ for i (./*.mp3){mpg321 --w - $i &gt; ${i:r}.wav}\r
766 \r
767 # Download with LaTeX2HTML  created Files (for example the ZSH-Guide):\r
768   $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do\r
769   &gt;     lynx -source $f &gt;${f:t}\r
770   &gt; done\r
771 \r
772 # Move all files in dir1 and dir2 that have line counts greater than 10 to\r
773 # another directory say "/more10"\r
774   $ mv dir[12]/**/*.cr(-.e{'((`wc -l &lt; $REPLY` &gt; 10))'}) /more10\r
775 \r
776 # Make with dpkg a master-list of everyfile that it has installed\r
777   $ diff &lt;(find / | sort) &lt;(cat /var/lib/dpkg/info/*.list | sort)\r
778 \r
779 # Replace this fucking Escape-Sequences:\r
780   $ autoload colors ; colors\r
781   $ print "$bg[cyan]$fg[blue]You are a idiot" &gt;&gt; /dev/pts/3\r
782 \r
783 # Get ASCII value of a character\r
784   $ char=N ; print $((#char))\r
785 \r
786 # Filename "Erweiterung"\r
787 # Note: The (N) says to use the nullglob option for this particular\r
788 # glob pattern.\r
789   $ for i in *.o(N); do\r
790   &gt;     rm $i\r
791   &gt; done\r
792 \r
793 # Rename files; i. e. FOO to foo and bar to BAR\r
794   $ for i in *(.); mv $i ${i:l} # `FOO' to `foo'\r
795   $ for i in *(.); mv $i ${i:u} # `bar to `BAR'\r
796 \r
797 # Show all suid-files in $PATH\r
798   $ ls -latg ${(s.:.)PATH} | grep '^...s'\r
799 # or more complex ;)\r
800   $ print -l ${^path}/*(Ns,S)\r
801 # or show only executables with a user given pattern\r
802   $ print -l ${^path}/*vim*(*N)\r
803 \r
804 # gzip files when containing a certain string\r
805   $ gzip ${(ps:\0:)"$(grep -lZ foobar ./*.txt(.))"}\r
806 \r
807 # A small  one-liner, that reads from stdin and prints to stdout the first\r
808 # unique line i. e. does not print lines that have been printed before\r
809 # (this is similar to the unique command, but unique can only handle\r
810 # adjacent lines).\r
811   $ IFS=$'\n\n'; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}\r
812 \r
813 # Lists every executable in PATH\r
814   $ print -l ${^path}/*(-*N)\r
815 \r
816 # Match all .c files in all subdirectories, _except_ any SCCS subdirectories?\r
817   $ ls **/*.c~(*/)#SCCS/*\r
818 \r
819 # List all `README' - files case-insensitive with max. one typo\r
820   $ ls **/*(#ia2)readme\r
821 \r
822 # case insensitive checking for variables\r
823   $ if [[ $OSTYPE == (#i)LINUX*(#I) ]]; then\r
824   &gt;    echo "Penguin on board."\r
825   &gt; else\r
826   &gt;    echo "Not a Linux."\r
827   &gt; fi</tt></pre>\r
828 </div></div>\r
829 <h3>(Recursive) Globbing - Examples</h3>\r
830 <p>A list of valid glob Qualifiers can be found in zshexpn(1). <strong>Note:</strong>\r
831 **/ is equivalent to (*/)#! For example:</p>\r
832 <div class="listingblock">\r
833 <div class="content">\r
834 <pre><tt>$ print (*/)#zsh_us.ps\r
835 zsh-4.2.3/Doc/zsh_us.ps\r
836 $ print **/zsh_us.ps\r
837 zsh-4.2.3/Doc/zsh_us.ps</tt></pre>\r
838 </div></div>\r
839 <div class="listingblock">\r
840 <div class="content">\r
841 <pre><tt># Search for `README' in all Subdirectories\r
842   $ ls -l **/README\r
843 \r
844 # find directories that contain both "index.php" and "index.html", or in\r
845 # general, directories that contain more than one file matching "index.*"\r
846   $ ls **/*(D/e:'[[ -e $REPLY/index.php &amp;&amp; -e $REPLY/index.html ]]':)\r
847   # or\r
848   $ ls **/*(D/e:'l=($REPLY/index.*(N)); (( $#l &gt;= 2 ))':)\r
849 \r
850 # Find command to search for directory name instead of basename\r
851   $ print -rl /**/*~^*/path(|/*)\r
852   # or - without Zsh\r
853   $ find / | grep -e /path/ -e '/path$'\r
854 \r
855 # Print he path of the directories holding the ten biggest C regular files\r
856 # in the current directory and subdirectories.\r
857   $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u\r
858 \r
859 # Find files with size == 0 and send a mail\r
860   $ files=(**/*(ND.L0m+0m-2))\r
861   &gt; (( $#files &gt; 0 )) &amp;&amp; print -rl -- $files | \\r
862     mailx -s "empty files" foo@bar.tdl\r
863 \r
864 # recursive chmod\r
865   $ chmod 700 **/(.) # Only files\r
866   $ chmod 700 **/(/) # Only directories\r
867 \r
868 # print out all of the files in that directory in 2 columns\r
869   $ print -rC2 -- ${1:[...]}/*(D:t)\r
870 #            ^- number ob columns\r
871 # or - if you feel concerned about special characters - use\r
872   $ list=(${1:[...]}/*(ND:t))\r
873   $ (($#list)) &amp;&amp; print -rC2 -- ${(V)list}\r
874 \r
875 # Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag\r
876 # (recursive, include  dotfiles) remove the setgid/setuid flag and print\r
877 # a message\r
878   $ chmod -s /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S))\r
879 # or with a small script\r
880   $ for file (/home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) {\r
881   &gt;    print -r -- $file\r
882   &gt;    chmod -s $file &amp;&amp; print -r fixed $file\r
883   &gt; }\r
884 # or use ``zargs'' (require autoload zargs) prevent the arg list too\r
885 # long error\r
886   $ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s\r
887 \r
888 # List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)\r
889   $ ls -l foo&lt;23-&gt;\r
890 \r
891 # get all files that begin with the date strings from June 4 through\r
892 # June 9 of 2004\r
893   $ ls -l 200406{04..10}*(N)\r
894 # or if they are of the form 200406XX (require ``setopt extended_glob''\r
895   $ ls -l 200306&lt;4-10&gt;.*\r
896 \r
897 # remove spaces from filenames\r
898   $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done\r
899 \r
900 # Show only all *.c and *.h - Files\r
901   $ ls -l *.(c|h)\r
902 \r
903 # Show only all *.c - files and ignore `foo.c'\r
904   $ ls *.c~foo.c\r
905 \r
906 # show data to *really* binary format\r
907   $ zsh -ec 'while {} {printf %.8x $n;repeat 8 \\r
908   &gt; {read -ku0 a printf \ %.8d $(([##2]#a))};print;((n+=8))}' &lt; binary\r
909 \r
910 # Show only world-readable files\r
911   $ ls -l *(R)\r
912 \r
913 # List files in the current directory are not writable by the owner\r
914   $ print -l ~/*(ND.^w)\r
915 \r
916 # find and delete the files which are older than a given parameter\r
917 # (seconds/minutes/hours)\r
918   # deletes all regular file in /Dir that are older than 3 hours\r
919    $ rm -f /Dir/**/*(.mh+3)\r
920   # deletes all symlinks in /Dir that are older than 3 minutes\r
921    $ rm -f /Dir/**/*(@mm+3)\r
922   # deletes all non dirs in /Dir that are older than 30 seconds\r
923    $ rm -f /Dir/**/*(ms+30^/)\r
924   # deletes all folders, sub-folders and files older than one hour\r
925    $ rm ./**/*(.Dmh+1,.DL0)\r
926   # deletes all files more than 6 hours old\r
927    $ rm -f **/*(mh+6)\r
928   # removes all files but the ten newer ones (delete all but last 10\r
929   # files in a directory)\r
930    $ rm ./*(Om[1,-11])\r
931  Note: If you get a arg list too long, you use the builtin rm. For\r
932        example:\r
933    $ zmodload zsh/files ; rm -f **/*(mh+6)\r
934   or use the zargs function:\r
935    $ autoload zargs ; zargs **/*(mh+6) -- rm -f\r
936 \r
937 # A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern\r
938 # Matching find all files in all subdirectories, searching recursively,\r
939 # which have a given name, case insensitive, are at least 50 KB large,\r
940 # no more than a week old and owned by the root user, and allowing up\r
941 # to a single error in the spelling of the name. In fact, the required\r
942 # expression looks like this:\r
943   $ ls **/(#ia1)name(LK+50mw-1u0)\r
944 \r
945 # Change the UID from 102 to 666\r
946   $ chown 666 **/*(u102)\r
947 \r
948 # List all files which have not been updated since last 10 hours\r
949   $ print -rl -- *(Dmh+10^/)\r
950 \r
951 # delete only the oldest file in a directory\r
952   $ rm ./*filename*(Om[1])\r
953 \r
954 # Sort the output from `ls -l' by file size\r
955   $ ls -fld *(OL)\r
956 \r
957 # find most recent file in a directory\r
958   $ setopt dotglob ; print directory/**/*(om[1])\r
959 \r
960 # Show only empty files which nor `group' or `world writable'\r
961   $ ls *(L0f.go-w.)\r
962 \r
963 # find - and list - the ten newest files in directories and subdirs\r
964 # (recursive)\r
965   $ print -rl -- **/*(Dom[1,10])\r
966 \r
967 # Print only 5 lines by "ls" command (like ``ls -laS | head -n 5'')\r
968   $ ls -fl *(DOL[1,5])\r
969 \r
970 # display the 5-10 last modified files\r
971   $ print -rl -- /path/to/dir/**/*(D.om[5,10])\r
972 \r
973 # find all files without a valid owner\r
974   $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(&lt;/etc/passwd)"}%%:*}:)\r
975 \r
976 # find all the empty directories in a tree\r
977   $ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] &amp;&amp; print $f; done\r
978 # Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.\r
979 # Hence *(F) indicates all subdirectories with entries, *(/^F) means all\r
980 # subdirectories with no entries.\r
981   $ ls -ld *(/^F)\r
982 \r
983 # remove empty directories afterwards\r
984   $ rmdir ./**/*(/od) 2&gt; /dev/null\r
985 \r
986 # Show only files are owned from group `users'\r
987   $ ls -l *(G[users])\r
988 </tt></pre>\r
989 </div></div>\r
990 <h3>Modifiers usage</h3>\r
991 <p>Modifiers are a powerful mechanism that let you modify the results\r
992 returned by parameter, filename and history expansion. See zshexpn(1)\r
993 for details.</p>\r
994 <div class="listingblock">\r
995 <div class="content">\r
996 <pre><tt>&lt;&lt;&lt;&lt;&lt;&lt;&lt; /home/dope/download/Source/HG-Repos/zsh-lovers/zsh-lovers.1.txt.orig.432616858\r
997 # NOTE: Zsh 4.3.4 needed!\r
998 $ autoload -U age\r
999 # files modified today\r
1000   $ print *(e:age today now:)\r
1001 # files modified since 5 pm\r
1002   $ print *(e-age 17:00 now-)\r
1003 # ... since 5 o'clock yesterda\r
1004   $ print *(e-age yesterday,17:00 now-)\r
1005 # ... from last Christmas before today\r
1006   $ print *(e-age 2006/12/25 today-)\r
1007 # ... before yesterday\r
1008   $ print *(e-age 1970/01/01 yesterday-)\r
1009 # all files modified between the start of those dates\r
1010   $ print *(e:age 2006/10/04 2006/10/09:)\r
1011 # all files modified on that date\r
1012   $ print *(e:age 2006/10/04:)\r
1013 # Supply times.\r
1014   $ print *(e-age 2006/10/04:10:15 2006/10/04:10:45-)\r
1015 \r
1016 # Remove a trailing pathname component, leaving the head. This works like\r
1017 ||||||| /tmp/zsh-lovers.1.txt~base.AvW_ZW\r
1018 # Remove a trailing pathname component, leaving the head. This works like\r
1019 =======\r
1020 # Remove a trailing pathname component, leaving the head. This works like\r
1021 &gt;&gt;&gt;&gt;&gt;&gt;&gt; /tmp/zsh-lovers.1.txt~other.vDaddL\r
1022 # `dirname'.\r
1023   $ echo =ls(:h)\r
1024   /bin\r
1025 \r
1026 # Remove all leading pathname components, leaving the tail. This works\r
1027 # like `basename'.\r
1028   $ echo =ls(:t)\r
1029   ls\r
1030 \r
1031 # Remove the suffix from each file (*.sh in this example)\r
1032    $f:e is $f file extension\r
1033    :h --&gt; head (dirname)\r
1034    :t --&gt; tail (basename)\r
1035    :r --&gt; rest (extension removed)\r
1036   $ for f (*.sh) mv $f $f:r\r
1037 \r
1038 # Remove a filename extension of the form `.xxx', leaving the root name.\r
1039   $ echo $PWD\r
1040   /usr/src/linux\r
1041   $ echo $PWD:t\r
1042   linux\r
1043 \r
1044 # Remove all but the extension.\r
1045   $ foo=23.42\r
1046   $ echo $foo\r
1047   23.42\r
1048   $ echo $foo:e\r
1049   42\r
1050 \r
1051 # Print the new command but do not execute it. Only works with history\r
1052 # expansion.\r
1053   $ echo =ls(:h)\r
1054   /bin\r
1055   $ !echo:p\r
1056   $ echo =ls(:h)\r
1057 \r
1058 # Quote the substituted words, escaping further substitutions.\r
1059   $ bar="23'42"\r
1060   $ echo $bar\r
1061   23'42\r
1062   $ echo $bar:q\r
1063   23\'42\r
1064 \r
1065 # Convert the words to all lowercase.\r
1066   $ bar=FOOBAR\r
1067   $ echo $bar\r
1068   FOOBAR\r
1069   $ echo $bar:l\r
1070   foobar\r
1071 \r
1072 # Convert the words to all uppercase.\r
1073   $ bar=foobar\r
1074   $ echo $bar\r
1075   foobar\r
1076   $ echo $bar:u\r
1077   FOOBAR\r
1078 \r
1079 # convert 1st char of a word to uppercase\r
1080   $ foo="one two three four"\r
1081   $ print -r -- "${(C)foo}"\r
1082   One Two Three Four</tt></pre>\r
1083 </div></div>\r
1084 <h3>Redirection-Examples</h3>\r
1085 <p>See zshmisc(1) for more informations (or less ${^fpath}/zmv(N))</p>\r
1086 <div class="listingblock">\r
1087 <div class="content">\r
1088 <pre><tt># Append `exit 1' at the end of all *.sh - files\r
1089   $ echo "exit 1" &gt;&gt; *.sh\r
1090 \r
1091 # adding files to foobar.tar.gz\r
1092   $ eval set =(gunzip &lt; foobar.tar.gz) '\r
1093      tar rf $1 additional.txt &amp;&amp;gzip &lt; $1 &gt; foobar.tar.gz'\r
1094 \r
1095 # Redirect output to a file AND display on screen\r
1096   $ foobar &gt;&amp;1 &gt; file1 &gt; file2 &gt; ..\r
1097 \r
1098 # pipe single output to multiple inputs\r
1099   $ zcat foobar.Z &gt;&gt; (gzip -9 &gt; file1.gz) \\r
1100       &gt;&gt; (bzip2 -9 &gt; file1.bz2) \\r
1101       &gt;&gt; (acb --best &gt; file1.acb)\r
1102 \r
1103 # Append /etc/services at the end of file `foo' and `bar'\r
1104   $ cat /etc/services &gt;&gt; foo &gt;&gt; bar\r
1105 \r
1106 # Pipe STDERR\r
1107   $ echo An error &gt;&amp;2 2&gt;&amp;1 | sed -e 's/A/I/'\r
1108 \r
1109 # send standard output of one process to standard input of several processes\r
1110 # in the pipeline\r
1111   $ setopt multios\r
1112   $ process1 &gt; &gt;(process1) &gt; &gt;(process2)\r
1113 \r
1114 # initializing a variable and simultaneously keeping terminal output\r
1115   $ setopt multios\r
1116   $ { a=$(command &gt;&amp;1 &gt;&amp; 3 3 &gt; &amp;- 2&gt;&amp;1);} 3&gt;&amp;1\r
1117 \r
1118 # redirect stderr two times\r
1119   $ setopt multios ; program 2&gt; file2 &gt; file1 2&gt;&amp;1\r
1120 \r
1121 # Duplicating stdout and stderr to a logfile\r
1122   $ exec 3&gt;&amp;1 &gt; logfile 2&gt;&amp;2 2&gt;&amp;1 &gt;&amp;3 3&gt;&amp;-\r
1123 \r
1124 # redirect stderr (only) to a file and to orig. stderr:\r
1125   $ command 2&gt;&amp;2 2&gt;stderr\r
1126 # redirect stderr and stdout to separate files and both to orig. stdout:\r
1127   $ command 2&gt;&amp;1 1&gt;&amp;1 2&gt;stderr 1&gt;stdout\r
1128 # redirect stderr and stdout to separate files and stdout to orig. stdout\r
1129 # AND stderr to orig. stderr:\r
1130   $ command 2&gt;&amp;2 1&gt;&amp;1 2&gt;stderr 1&gt;stdout\r
1131 \r
1132 # More fun with STDERR ;)\r
1133   $ ./my-script.sh 2&gt; &gt;(grep -v moron &gt;error.log)|process-output &gt;output.log\r
1134   $  echo "Thats STDOUT" &gt;&gt;(sed 's/stdout/another example/' &gt; foobar)</tt></pre>\r
1135 </div></div>\r
1136 <h3>ZMV-Examples (require autoload zmv)</h3>\r
1137 <p><strong>Note:</strong> <em>-n</em> means no execution (just print what would happen). At</p>\r
1138 <div class="listingblock">\r
1139 <div class="content">\r
1140 <pre><tt># remove round bracket within filenames\r
1141 # i. e. foo-(bar).avi -&gt; foo-bar.avi\r
1142   $ zmv '*' '${f//[()]/}'\r
1143 \r
1144 # serially all files (foo.foo &gt; 1.foo, fnord.foo &gt; 2.foo, ..)\r
1145   $ autoload zmv\r
1146   $ ls *\r
1147   1.c  asd.foo  bla.foo  fnord.foo  foo.fnord  foo.foo\r
1148   $ c=1 zmv '*.foo' '$((c++)).foo'\r
1149   $ ls *\r
1150   1.c  1.foo  2.foo  3.foo  4.foo  foo.fnord\r
1151 \r
1152 # Rename "file.with.many.dots.txt" by substituting dots (exept for the last\r
1153 # one!) with a space\r
1154   $ touch {1..20}-file.with.many.dots.txt\r
1155   $ zmv '(*.*)(.*)' '${1//./ }$2'\r
1156 \r
1157 # Remove the first 4 chars from a filename\r
1158   $ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!\r
1159 \r
1160 # Rename names of all files under the current Dir to lower case, but keep\r
1161 # dirnames as-is.\r
1162   $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'\r
1163 \r
1164 # replace all 4th character, which is "1",  with "2" and so on\r
1165   $ autoload -U zmv\r
1166   $ zmv '(???)1(???[1-4].txt)' '${1}2${2}'\r
1167 \r
1168 # Remove the first 15 characters from a string\r
1169   $ touch 111111111111111{a-z}\r
1170   $ autoload zmv\r
1171   $ zmv '*' '$f[16,-1]'\r
1172 \r
1173 # Replace spaces (any number of them) with a single dash in file names\r
1174   $ autload zmv\r
1175   $ zmv -n '(**/)(* *)' '$1${2//( #-## #| ##)/-}'\r
1176   # or - with Bash\r
1177   $ find . -depth -name '* *' -exec bash -c '\r
1178   &gt; shopt -s extglob\r
1179   &gt; file=$1\r
1180   &gt; dir=${file%/*}\r
1181   &gt; name=${file##*/}\r
1182   &gt; newname=${name//*([ -]) *([ -])/-}\r
1183   &gt; mv -i -- "$file" "$Dir/$newname"' {} {} \;\r
1184 \r
1185 # Clean up file names and remove special characters\r
1186   $ autoload zmv\r
1187   $ zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9._]/_}'\r
1188 \r
1189 # Add *.py to a bunch of python scripts in a directory (some of them end\r
1190 # in *.py and give them all a proper extension\r
1191   $ autoload zmv\r
1192   $ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'\r
1193 \r
1194 # lowercase all extensions (i. e. *.JPG) incl. subfolders\r
1195   $ autoload zmv\r
1196   $ zmv '(**/)(*).(#i)jpg' '$1$2.jpg'\r
1197   # Or - without Zsh\r
1198   $ find Dir -name '*.[jJ][pP][gG]' -print | while read f\r
1199   &gt; do\r
1200   &gt;      case $f in\r
1201   &gt;       *.jpg) ;\r
1202   &gt;       *) mv "$f" "${f%.*}.jpg" ;\r
1203   &gt;       esac\r
1204   &gt; done\r
1205 \r
1206 # remove leading zeros from file extension\r
1207   $ autoload zmv\r
1208   $ ls\r
1209   filename.001  filename.003  filename.005  filename.007  filename.009\r
1210   filename.002  filename.004  filename.006  filename.008  filename.010\r
1211   $ zmv '(filename.)0##(?*)' '$1$2'\r
1212   $ ls\r
1213   filename.1  filename.10  filename.2  filename.3  filename.4  filename.5 ..\r
1214 \r
1215 # renumber files.\r
1216   $ autoload zmv\r
1217   $ ls *\r
1218   foo_10.jpg  foo_2.jpg  foo_3.jpg  foo_4.jpg  foo_5.jpg  foo_6.jpg ..\r
1219   $ zmv -fQ 'foo_(&lt;0-&gt;).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'\r
1220   $ ls *\r
1221   foo_10.jpg  foo_11.jpg  foo_3.jpg  foo_4.jpg  foo_5.jpg  ...\r
1222 \r
1223 # adding leading zeros to a filename (1.jpg -&gt; 001.jpg, ..\r
1224   $ autoload zmv\r
1225   $ zmv '(&lt;1-&gt;).jpg' '${(l:3::0:)1}.jpg'\r
1226 \r
1227 # See above, but now only files with a filename &gt;= 30 chars\r
1228   $ autoload zmv\r
1229   $ c=1 zmv "${(l:30-4::?:)}*.foo" '$((c++)).foo'\r
1230 \r
1231 # Replace spaces in filenames with a underline\r
1232   $ autoload zmv\r
1233   $ zmv '* *' '$f:gs/ /_'\r
1234 \r
1235 # Change the suffix from *.sh to *.pl\r
1236   $ autoload zmv\r
1237   $ zmv -W '*.sh' '*.pl'\r
1238 \r
1239 # Add a "".txt" extension to all the files within ${HOME}\r
1240   # ``-.'' is to only rename regular files or symlinks to regular files,\r
1241   # ``D'' is to also rename hidden files (dotfiles))\r
1242   $ autoload zmv\r
1243   $ zmv -Q '/home/**/*(D-.)' '$f.txt'\r
1244   # Or to only rename files that don't have an extension:\r
1245   $ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'\r
1246 \r
1247 # Recursively change filenames with characters ? [ ] / = + &lt; &gt; ; : " , - *\r
1248   $ autoload zmv\r
1249   $ chars='[][?=+&lt;&gt;;",*-]'\r
1250   $ zmv '(**/)(*)' '$1${2//$~chars/%}'\r
1251 \r
1252 # Removing single quote from filenames (recursively)\r
1253   $ autoload zmv\r
1254   $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"\r
1255 \r
1256 # When a new file arrives (named file.txt) rename all files in order to\r
1257 # get (e. g. file119.txt becomes file120.txt, file118.txt becomes\r
1258 # file119.txt and so on ending with file.txt becoming file1.txt\r
1259   $ autoload zmv\r
1260   $ zmv -fQ 'file([0-9]##).txt(On)' 'file$(($1 + 1)).txt'\r
1261 \r
1262 # lowercase/uppercase all files/directories\r
1263   $ autoload zmv\r
1264   $ zmv '(*)' '${(L)1}' # lowercase\r
1265   $ zmv '(*)' '${(U)1}' # uppercase\r
1266 \r
1267 # Remove the suffix *.c from all C-Files\r
1268   $ autoload zmv\r
1269   $ zmv '(*).c' '$1'\r
1270 \r
1271 # Uppercase only the first letter of all *.mp3 - files\r
1272   $ autoload zmv\r
1273   $ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'\r
1274 \r
1275 # Copy the target `README' in same directory as each `Makefile'\r
1276   $ autoload zmv\r
1277   $ zmv -C '(**/)Makefile' '${1}README'\r
1278 \r
1279 # Removing single quote from filenames (recursively)\r
1280   $ autoload zmv\r
1281   $ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"\r
1282 \r
1283 # Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..\r
1284   $ autoload zmv\r
1285   $ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'\r
1286   $ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively</tt></pre>\r
1287 </div></div>\r
1288 <h3>Module-Examples</h3>\r
1289 <p>Please read zshmodules(1) first!</p>\r
1290 <h4>zsh/pcre (require zmodload zsh/pcre)</h4>\r
1291 <div class="listingblock">\r
1292 <div class="content">\r
1293 <pre><tt># Copy files of a certain period (date indicated in the filenames)\r
1294   $ zmodload zsh/pcre\r
1295   $ ls -d -- *(e:'[[ $REPLY -pcre-match pcre-regexp ]]':)\r
1296   # or\r
1297   $ m() { [[ $1 -pcre-match pcre-regexp ]] }\r
1298   $ ls -d -- *(+m)</tt></pre>\r
1299 </div></div>\r
1300 <h4>zsh/clone (require zmodload zsh/clone)</h4>\r
1301 <div class="listingblock">\r
1302 <div class="content">\r
1303 <pre><tt># Creates a forked instance of the current shell ($! is set to zero) and\r
1304 # execute ``command'' on /dev/tty8 (for this example).\r
1305   $ zmodload zsh/clone\r
1306   $ clone /dev/tty8 &amp;&amp; (($! == 0)) &amp;&amp; exec command</tt></pre>\r
1307 </div></div>\r
1308 <h4>zsh/datetime (require zmodload zsh/datetime)</h4>\r
1309 <div class="listingblock">\r
1310 <div class="content">\r
1311 <pre><tt>  $ zmodload zsh/datetime\r
1312   $ alias datereplacement='strftime "%Y-%m-%d" $EPOCHSECONDS'\r
1313   $ export DATE=`datereplacement`\r
1314   $ echo $DATE\r
1315 \r
1316 #  strip date from filename\r
1317   $ $ zmodload zsh/datetime\r
1318   $ setopt extendedglob\r
1319   $ touch aaa_bbb_20041212_c.dat eee_fff_20051019_g.dat\r
1320   $ strftime -s pattern \\r
1321     '???_???_&lt;0-%Y%m%d&gt;_?.dat' $((EPOCHSECONDS - 365 * 24 * 60 * 60 / 2))\r
1322   $ print -rl -- $~pattern\r
1323   aaa_bbb_20041212_c.dat\r
1324   $ print -rl -- $pattern\r
1325   ???_???_&lt;0-20050815&gt;_?.dat\r
1326 \r
1327 # Search files size == 0, to be based on the file name containing a date\r
1328 # rather than the "last modified" date of the file\r
1329   $ zmodload -i zsh/datetime\r
1330   $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))\r
1331   $ files=(**/$file(N.L0))\r
1332   $ (( $#files &gt; 0 )) &amp;&amp; print -rl -- $files | \\r
1333     mailx -s "empty files"  foo@bar.tdl</tt></pre>\r
1334 </div></div>\r
1335 <h4>zsh/stat (require zmodload zsh/stat)</h4>\r
1336 <div class="listingblock">\r
1337 <div class="content">\r
1338 <pre><tt># test if a symbolic link links to a certain file\r
1339   $ zmodload -i zsh/stat\r
1340   $ ! stat -LH s foo.ln || [[ $s[link] != "foo.exe" ]] || ln -sf foo.exe foo.ln\r
1341 \r
1342 # comparing file dates\r
1343   $ zmodload zsh/stat\r
1344   $ file1=foo\r
1345   $ file2=bar\r
1346   $ touch bar &amp; sleep 5 &amp; touch foo\r
1347   $ echo $file1 is $(($(stat +mtime $file2) - \\r
1348     $(stat +mtime $file1))) seconds older than $file2.\r
1349   bar is 5 seconds older than foo\r
1350 \r
1351 # list the files of a disk smaller than some other file\r
1352   $ zmodload zsh/stat\r
1353   $ stat -A max +size some-other-file\r
1354   $ print -rl ./**/*(D.L-$max)\r
1355 \r
1356 # List the top 100 biggest files in a disk\r
1357   $ zmodload zsh/stat\r
1358   $ ls -fld ./**/*(d`stat +device .`OL[1,100])\r
1359 \r
1360 # Get only the user name and the file names from (like\r
1361 # ls -l * | awk '{print $3" " $8}')\r
1362   $ zmodload zsh/stat\r
1363   $ for file; do\r
1364   &gt;   stat -sA user +uid -- "$file" &amp;&amp;\r
1365   &gt;     print -r -- "$user" "$file"\r
1366   &gt; done\r
1367 \r
1368 # get the difference between actual bytes of file and allocated bytes of file\r
1369   $ zmodload zsh/stat\r
1370   $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))\r
1371 \r
1372 # Find largest file\r
1373 # ``D''  : to include dot files (d lowercase is for device)\r
1374 # ``O''  : reverse Ordered (o lowercase for non-reverse order)\r
1375 # ``L''  : by file Length (l is for number of links)\r
1376 # ``[1]'': return only first one\r
1377   $ zmodload zsh/stat\r
1378   $ stat +size ./*(DOL[1])\r
1379 \r
1380 # file size in bytes\r
1381   $ zmodload zsh/stat\r
1382   $ stat -L +size ~/.zshrc\r
1383   4707\r
1384 \r
1385 # Delete files in a directory that hasn't been accessed in the last ten days\r
1386 # and send ONE mail to the owner of the files informing him/her of the files'\r
1387 # deletion.\r
1388   $ zmodload zsh/stat zsh/files\r
1389   $ typeset -A f; f=()\r
1390   $ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})\r
1391   $ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}\r
1392 \r
1393 # Get a "ls -l" on all the files in the tree that are younger than a\r
1394 # specified age\r
1395   $ zmodload zsh/stat\r
1396   $ for d (. ./**/*(N/m-2))\r
1397   &gt;   print -r -- $'\n'$d: &amp;&amp; cd $d &amp;&amp; {\r
1398   &gt;      for f (*(Nm-2om))\r
1399   &gt;   stat -F '%b %d %H:%M' -LsAs -- $f &amp;&amp;\r
1400   &gt;   print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \\r
1401   &gt;   ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-&gt; $s[14]}\r
1402   &gt;   cd ~-\r
1403   &gt; }\r
1404 \r
1405 # get file creation date\r
1406   $ zmodload zsh/stat\r
1407   $ stat -F '%d %m %Y' +mtime ~/.zshrc\r
1408   30 06 2004\r
1409   $ stat -F '%D' +mtime ~/.zshrc\r
1410   06/30/04</tt></pre>\r
1411 </div></div>\r
1412 <h4>zsh/files (require zmodload zsh/files)</h4>\r
1413 <div class="listingblock">\r
1414 <div class="content">\r
1415 <pre><tt># search a directory for files containing a certain string then copy those\r
1416 # files to another directory.\r
1417   $ zmodload zsh/files\r
1418   $ IFS=$'\0'\r
1419   $ cp $(grep -lZr foobar .) otherdirectory</tt></pre>\r
1420 </div></div>\r
1421 <h4>zsh/mapfile (require zmodload zsh/mapfile)</h4>\r
1422 <div class="listingblock">\r
1423 <div class="content">\r
1424 <pre><tt># grepping for two patterns\r
1425   $ zmodload zsh/mapfile\r
1426   $ pattern1="foo"\r
1427   $ pattern2="bar foo"\r
1428   $ print -l ./**/*(DN.e{'z=$mapfile[$REPLY] &amp;&amp; [[ $z = *$pattern1* &amp;&amp; \\r
1429     $z = *$pattern2* ]]'})\r
1430 # or a solution in combination with zsh/pcre\r
1431   $ zmodload -i zsh/mapfile zsh/pcre\r
1432   $ pattern1="foo"\r
1433   $ pattern2="bar foo"\r
1434   $ pcre_compile "(?s)(?=.*?$pattern1).*?$pattern2"\r
1435   $ pcre_study\r
1436   $ print -l ./**/*(DN.e{'pcre_match $mapfile[$REPLY]'})\r
1437 \r
1438 # equivalent for ``less /etc/passwd | grep -v root''\r
1439   $ zmodload zsh/mapfile\r
1440   $ IFS=$'\n\n'\r
1441   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}\r
1442 # or - for case insensitive\r
1443   $ setopt extendedglob\r
1444   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}\r
1445 \r
1446 # If a XML-file contains stuff like ``&lt;TAGA/&gt;'' and ``&lt;TAGB/&gt;'', number\r
1447 # this empty tags (ones ending in '/&gt;') so if encountered in the same\r
1448 # order, the preceeding tags would become ``&lt;TAGA/&gt;1&lt;/TAGA&gt;'' and\r
1449 # ``&lt;TAGB/&gt;2&lt;/TAGB&gt;''\r
1450   $ zmodload zsh/mapfile\r
1451   $ cnt=0\r
1452   $ apfile[data.xml.new]=${(S)mapfile[data.xml]//\\r
1453   &gt; (#im)&lt;TAGA&gt;*&lt;\/TAGA&gt;/&lt;TAGA&gt;$((++cnt))&lt;\/TAGA&gt;}\r
1454 \r
1455 # removing all files in users Maildir/new that contain ``filename="gone.src''\r
1456   $ zmodload zsh/{files,mapfile}\r
1457   $ rm -f /u1/??/*/Maildir/new/100*(.e{'[[ $mapfile[$REPLY] == \\r
1458     *filename=\"gone.scr\"* ]]'})\r
1459 \r
1460 # Grep out the Title from a postscript file and append that value to the\r
1461 # end of the filename\r
1462   $ autoload -U zmv\r
1463   $ zmodload zsh/mapfile\r
1464   $ zmv '(*).ps' '$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps'</tt></pre>\r
1465 </div></div>\r
1466 <h4>zsh/mathfunc (require zmodload zsh/mathfunc)</h4>\r
1467 <div class="listingblock">\r
1468 <div class="content">\r
1469 <pre><tt>$ zmodload zsh/mathfunc\r
1470 $ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))\r
1471   -1.1102230246251565e-16\r
1472 $ echo $(( pi = 4.0 * atan(1.0) ))\r
1473   3.1415926535897931\r
1474 $ echo $(( f = sin(0.3) ))\r
1475   0.29552020666133955\r
1476 $ print $((1e12 * rand48()))\r
1477   847909677310.23413\r
1478 $ print $(( rand48(seed) ))\r
1479   0.01043488334700271</tt></pre>\r
1480 </div></div>\r
1481 <h4>zsh/termcap (require zmodload zsh/termcap)</h4>\r
1482 <div class="listingblock">\r
1483 <div class="content">\r
1484 <pre><tt> $ zmodload -ab zsh/termcap echotc\r
1485  $ GREEN=`echotc AF 2`\r
1486  $ YELLOW=`echotc AF 3`\r
1487  $ RED=`echotc AF 1`\r
1488  $ BRIGHTRED=`echotc md ; echotc AF 1`\r
1489  $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred</tt></pre>\r
1490 </div></div>\r
1491 <h4>zsh/zpty (require zmodload zsh/zpty)</h4>\r
1492 <div class="listingblock">\r
1493 <div class="content">\r
1494 <pre><tt>  $ zmodload zsh/zpty\r
1495   $ zpty PW passwd $1\r
1496   $ zpty PW passwd $1\r
1497 # ``-r'': read the output of the command name.\r
1498 # ``z'' : Parameter\r
1499   $ zpty -r PW z '*password:'\r
1500 # send the to command name the given strings as input\r
1501   $ zpty -w PW $2\r
1502   $ zpty -r PW z '*password:'\r
1503   $ zpty -w PW $2\r
1504 # The second form, with the -d option, is used to delete commands\r
1505 # previously started, by supplying a list of their names. If no names\r
1506 # are given, all commands are deleted. Deleting a command causes the HUP\r
1507 # signal to be sent to the corresponding process.\r
1508   $ zpty -d PW</tt></pre>\r
1509 </div></div>\r
1510 <h4>zsh/net/socket (require zmodload zsh/net/socket)</h4>\r
1511 <div class="listingblock">\r
1512 <div class="content">\r
1513 <pre><tt># ``-l'': open a socket listening on filename\r
1514 # ``-d'': argument will be taken as the target file descriptor for the\r
1515 #         connection\r
1516 # ``3'' : file descriptor. See ``A User's Guide to the Z-Shell''\r
1517 #         (3.7.2: File descriptors)\r
1518   $ zmodload zsh/net/socket\r
1519   $ zsocket -l -d 3\r
1520 # ``-a'': accept an incoming connection to the socket\r
1521   $ zsocket -a -d 4 3\r
1522   $ zsocket -a -d 5 3 # accept a connection\r
1523   $ echo foobar &gt;&amp;4\r
1524   $ echo barfoo &gt;&amp;5\r
1525   $ 4&gt;&amp;- 5&gt;&amp;- 3&gt;&amp;</tt></pre>\r
1526 </div></div>\r
1527 <h4>zsh/zftp (require zmodload zsh/zftp)</h4>\r
1528 <div class="listingblock">\r
1529 <div class="content">\r
1530 <pre><tt> $ autoload -U zfinit\r
1531  $ zfinit\r
1532  $ zfparams www.example.invalid myuserid mypassword\r
1533  $ zfopen\r
1534  $ zfcd tips\r
1535  $ zfls -l zshtips.html\r
1536  $ zfput zshtips.html\r
1537  $ zfls -l zshtips.html\r
1538 \r
1539 # Automatically transfer files using FTP with error checking\r
1540   $ autoload -U zfinit ; zfinit\r
1541   $ zftp open host.name.invalid user passwd || exit\r
1542   $ zftp get /remote/file &gt; /local/file; r=$?\r
1543   $ zftp close &amp;&amp; exit r\r
1544 \r
1545 # compress and ftp on the fly\r
1546   $ autoload -U zfinit ; zfinit\r
1547   $ zftp open host.name.invalid user password\r
1548   $ zftp get $file | bzip2 &gt; ${file}.bz2\r
1549   $ zftp close\r
1550 \r
1551 # Recursice ``get''\r
1552   $ autoload -U zfinit ; zfinit\r
1553   $ zfanon cr.yp.to\r
1554   $ zfcd daemontools\r
1555   $ for file in `zfls` ; do\r
1556   &gt;     zfget $file\r
1557   $ done\r
1558   $ zfclose\r
1559 \r
1560 # Upload all regular files in $HOME/foobar (recursive) that are newer than\r
1561 # two hours to ftp.foobar.invalid/path/to/upload\r
1562   $ autoload -U zfinit ; zfinit\r
1563   $ zfopen ftp.foobar.invalid/path/to/upload\r
1564   $ cd $HOME/foobar\r
1565   $ zfput -r **/*(.mh-2)\r
1566   $ zfclose\r
1567 \r
1568 # long list of files on a ftp\r
1569   $ autoload -U zfinit ; zfinit\r
1570   $ zfopen some-host\r
1571   $ zfcd /some/remote/Dir\r
1572   $ cd /some/local/Dir\r
1573 # If the list.txt is located on the remote host, change to\r
1574 # zfget ${(f)"$(zftp get /path/to/remote/list.txt)"}\r
1575   $ zfget ${(f)"$(cat list.txt)"}\r
1576   $ zfclose</tt></pre>\r
1577 </div></div>\r
1578 <h4>zsh/zselect (require zmodload zsh/zselect)</h4>\r
1579 <div class="listingblock">\r
1580 <div class="content">\r
1581 <pre><tt># It's similar to\r
1582  ,----\r
1583  | $ sg=$(stty -g)\r
1584  | $ stty -icanon min 0 time 50\r
1585  | $ read yesno\r
1586  | $ stty "$sg"\r
1587  | $ case "$yesno" in\r
1588  | &gt;  yes) command1;;\r
1589  | &gt;  *) command2;;\r
1590  | &gt; esac\r
1591  `----\r
1592 $ zmodload zsh/zselect\r
1593 $ if zselect -t 500 -r 0 &amp;&amp; read yesno &amp;&amp; [ yes = "$yesno" ]; then\r
1594 &gt;    command1\r
1595 &gt; else\r
1596 &gt;    command1\r
1597 &gt; fi</tt></pre>\r
1598 </div></div>\r
1599 </div>\r
1600 <h2>OPTIONS</h2>\r
1601 <div class="sectionbody">\r
1602 <h3>Navigation options</h3>\r
1603 <p><strong>auto_cd</strong> (allow one to change to a directory by entering it as a\r
1604 command). <strong>auto_pushd</strong> (automatically append dirs to the push/pop list)\r
1605 pushd_ignore_dups (and don't duplicate them).</p>\r
1606 <h3>Misc</h3>\r
1607 <p><strong>no_hup</strong> (don't send  HUP signal to background jobs when exiting ZSH).\r
1608 <strong>print_exit_value</strong> (show a message with the exit code when a command\r
1609 returns with a non-zero exit code)</p>\r
1610 <h4>History options</h4>\r
1611 <p><strong>hist_verify</strong> (let the user edit the command line after history\r
1612 expansion (e.g. !ls) instead of immediately running it) <tt>\r
1613 Use the same history file for all sessions : </tt>\r
1614 <strong>setopt SHARE_HISTORY</strong></p>\r
1615 <h4>Privacy / Security</h4>\r
1616 <p><strong>no_clobber</strong>  (or set -C; prevent <em>&gt;</em> redirection from truncating\r
1617 the given file if it already exists)</p>\r
1618 <h4>Spelling correction</h4>\r
1619 <p><strong>correct</strong> (automatically correct the spelling of commands).\r
1620 <strong>correct_all</strong> (automatically correct the spelling of each word on the\r
1621 command line) <strong>dvorak</strong> (dvorak layout)</p>\r
1622 </div>\r
1623 <h2>UNSORTED/MISC</h2>\r
1624 <div class="sectionbody">\r
1625 <p>Mailpath: simple multiple mailpath:</p>\r
1626 <div class="listingblock">\r
1627 <div class="content">\r
1628 <pre><tt>mailpath=($HOME/Mail/mbox'?new mail in mbox'\r
1629           $HOME/Mail/tux.u-strasbg'?new mail in tux'\r
1630           $HOME/Mail/lilo'?new mail in lilo'\r
1631           $HOME/Mail/ldap-fr'?new mail in ldap-fr')</tt></pre>\r
1632 </div></div>\r
1633 <p>Mailpath: dynamic mailpath:</p>\r
1634 <div class="listingblock">\r
1635 <div class="content">\r
1636 <pre><tt>typeset -a mailpath\r
1637 for i in ~/Mail/Lists/*(.); do\r
1638    mailpath[$#mailpath+1]="${i}?You have new mail in ${i:t}."\r
1639 done</tt></pre>\r
1640 </div></div>\r
1641 <p>Avoid globbing on special commands:</p>\r
1642 <div class="listingblock">\r
1643 <div class="content">\r
1644 <pre><tt>for com in alias expr find mattrib mcopy mdir mdel which;\r
1645 alias $com="noglob $com"</tt></pre>\r
1646 </div></div>\r
1647 <p>For migrating your bashprompt to zsh use the script bash2zshprompt located in\r
1648 the zsh source distribution under <em>Misc</em>.</p>\r
1649 <p>For migration from (t)csh to zsh use the c2z tool that converts csh\r
1650 aliases and environment and shell variables to zsh. It does this by running\r
1651 csh, and having csh report on aliases and variables. The script then converts\r
1652 these to zsh startup files. It has some issues and usage information that are\r
1653 documented at the top of this script.</p>\r
1654 <p>Here are functions to set the title and hardstatus of an <strong>XTerm</strong> or of <strong>GNU\r
1655 Screen</strong> to <em>zsh</em> and the current directory, respectively, when the prompt is\r
1656 displayed, and to the command name and rest of the command line, respectively,\r
1657 when a command is executed:</p>\r
1658 <div class="listingblock">\r
1659 <div class="content">\r
1660 <pre><tt>function title {\r
1661       if [[ $TERM == "screen" ]]; then\r
1662         # Use these two for GNU Screen:\r
1663         print -nR $' 33k'$1$' 33'\\r
1664         print -nR $' 33]0;'$2$''\r
1665       elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then\r
1666         # Use this one instead for XTerms:\r
1667         print -nR $' 33]0;'$*$''\r
1668       fi\r
1669 }\r
1670 function precmd { title zsh "$PWD" }\r
1671 function preexec {\r
1672     emulate -L zsh\r
1673     local -a cmd; cmd=(${(z)1})\r
1674     title $cmd[1]:t "$cmd[2,-1]"\r
1675 }</tt></pre>\r
1676 </div></div>\r
1677 <p>Put the following line into your ~/.screenrc to see this fancy hardstatus:</p>\r
1678 <div class="listingblock">\r
1679 <div class="content">\r
1680 <pre><tt>caption always "%3n %t%? (%u)%?%?: %h%?"</tt></pre>\r
1681 </div></div>\r
1682 <p>Special variables which are assigned:</p>\r
1683 <div class="listingblock">\r
1684 <div class="content">\r
1685 <pre><tt>$LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS $UID\r
1686 $EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath</tt></pre>\r
1687 </div></div>\r
1688 </div>\r
1689 <h2>LINKS</h2>\r
1690 <div class="sectionbody">\r
1691 <dl>\r
1692 <dt>\r
1693 Primary site\r
1694 </dt>\r
1695 <dd>\r
1696 <p>\r
1697   <strong><a href="http://www.zsh.org/">http://www.zsh.org/</a></strong>\r
1698 </p>\r
1699 </dd>\r
1700 <dt>\r
1701 Project-page\r
1702 </dt>\r
1703 <dd>\r
1704 <p>\r
1705   <strong><a href="http://sourceforge.net/projects/zsh/">http://sourceforge.net/projects/zsh/</a></strong>\r
1706 </p>\r
1707 </dd>\r
1708 <dt>\r
1709 Z shell page at sunsite.dk\r
1710 </dt>\r
1711 <dd>\r
1712 <p>\r
1713     <strong><a href="http://zsh.sunsite.dk/">http://zsh.sunsite.dk/</a></strong>\r
1714 </p>\r
1715 </dd>\r
1716 <dt>\r
1717 From Bash to Z Shell: Conquering the Command Line - the book\r
1718 </dt>\r
1719 <dd>\r
1720 <p>\r
1721     <strong><a href="http://www.bash2zsh.com/">http://www.bash2zsh.com/</a></strong>\r
1722 </p>\r
1723 </dd>\r
1724 <dt>\r
1725 Mailinglistarchive\r
1726 </dt>\r
1727 <dd>\r
1728 <p>\r
1729     <strong><a href="http://www.zsh.org/mla/">http://www.zsh.org/mla/</a></strong>\r
1730 </p>\r
1731 </dd>\r
1732 <dt>\r
1733 ZSH-FAQ\r
1734 </dt>\r
1735 <dd>\r
1736 <p>\r
1737     <strong><a href="http://www.zsh.org/FAQ/">http://www.zsh.org/FAQ/</a></strong>\r
1738 </p>\r
1739 </dd>\r
1740 <dt>\r
1741 Userguide\r
1742 </dt>\r
1743 <dd>\r
1744 <p>\r
1745     <strong><a href="http://zsh.sunsite.dk/Guide/">http://zsh.sunsite.dk/Guide/</a></strong>\r
1746 </p>\r
1747 </dd>\r
1748 <dt>\r
1749 ZSH-Wiki\r
1750 </dt>\r
1751 <dd>\r
1752 <p>\r
1753     <strong><a href="http://www.zshwiki.org/">http://www.zshwiki.org/</a></strong>\r
1754 </p>\r
1755 </dd>\r
1756 <dt>\r
1757 Die Zsh als interaktive Shell\r
1758 </dt>\r
1759 <dd>\r
1760 <p>\r
1761     <strong><a href="http://cssun.rrze.uni-erlangen.de/~sipakale/zshreferat.html">http://cssun.rrze.uni-erlangen.de/~sipakale/zshreferat.html</a></strong>\r
1762 </p>\r
1763 </dd>\r
1764 <dt>\r
1765 A short introduction from BYU\r
1766 </dt>\r
1767 <dd>\r
1768 <p>\r
1769     <strong><a href="http://docs.cs.byu.edu/docs/zsh/index.php">http://docs.cs.byu.edu/docs/zsh/index.php</a></strong>\r
1770 </p>\r
1771 </dd>\r
1772 <dt>\r
1773 Mouse-Support ;)\r
1774 </dt>\r
1775 <dd>\r
1776 <p>\r
1777     <strong><a href="http://stchaz.free.fr/mouse.zsh">http://stchaz.free.fr/mouse.zsh</a></strong>\r
1778 </p>\r
1779 </dd>\r
1780 <dt>\r
1781 Shell Corner: Zsh Suite of "keeper" Functions\r
1782 </dt>\r
1783 <dd>\r
1784 <p>\r
1785     <strong><a href="http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm">http://www.unixreview.com/documents/s=9513/ur0501a/ur0501a.htm</a></strong>\r
1786 </p>\r
1787 </dd>\r
1788 <dt>\r
1789 The Z Shell (A Fan Page)\r
1790 </dt>\r
1791 <dd>\r
1792 <p>\r
1793     <strong><a href="http://www.princeton.edu/~kmccarty/zsh.html">http://www.princeton.edu/~kmccarty/zsh.html</a></strong>\r
1794 </p>\r
1795 </dd>\r
1796 <dt>\r
1797 Making the Transition to Zsh\r
1798 </dt>\r
1799 <dd>\r
1800 <p>\r
1801     <strong><a href="http://www.linux-mag.com/cgi-bin/printer.pl?issue=2002-05&amp;article=power">http://www.linux-mag.com/cgi-bin/printer.pl?issue=2002-05&amp;article=power</a></strong>\r
1802 </p>\r
1803 </dd>\r
1804 <dt>\r
1805 Curtains up: introducing the Z shell\r
1806 </dt>\r
1807 <dd>\r
1808 <p>\r
1809     <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
1810 </p>\r
1811 </dd>\r
1812 <dt>\r
1813 ZSH-Liebhaberseite\r
1814 </dt>\r
1815 <dd>\r
1816 <p>\r
1817     <strong><a href="http://michael-prokop.at/computer/tools_zsh_liebhaber.html">http://michael-prokop.at/computer/tools_zsh_liebhaber.html</a></strong>\r
1818 </p>\r
1819 </dd>\r
1820 <dt>\r
1821 ZSH-Seite von Michael Prokop\r
1822 </dt>\r
1823 <dd>\r
1824 <p>\r
1825     <strong><a href="http://www.michael-prokop.at/computer/tools_zsh.html">http://www.michael-prokop.at/computer/tools_zsh.html</a></strong>\r
1826 </p>\r
1827 </dd>\r
1828 <dt>\r
1829 A Case for the Z Shell on <strong><a href="http://www.daemonnews.org/">http://www.daemonnews.org/</a></strong>\r
1830 </dt>\r
1831 <dd>\r
1832 <p>\r
1833     <strong><a href="http://ezine.daemonnews.org/199910/zsh.html">http://ezine.daemonnews.org/199910/zsh.html</a></strong>\r
1834 </p>\r
1835 </dd>\r
1836 <dt>\r
1837 ZSH-Section from Dotfiles.com\r
1838 </dt>\r
1839 <dd>\r
1840 <p>\r
1841     <strong><a href="http://www.dotfiles.com/index.php?app_id=4">http://www.dotfiles.com/index.php?app_id=4</a></strong>\r
1842 </p>\r
1843 </dd>\r
1844 <dt>\r
1845 Writing Zsh Completion Functions\r
1846 </dt>\r
1847 <dd>\r
1848 <p>\r
1849     <strong><a href="http://www.linux-mag.com/2002-07/power_01.html">http://www.linux-mag.com/2002-07/power_01.html</a></strong>\r
1850 </p>\r
1851 </dd>\r
1852 <dt>\r
1853 ZSH Prompt introduction\r
1854 </dt>\r
1855 <dd>\r
1856 <p>\r
1857     <strong><a href="http://aperiodic.net/phil/prompt/">http://aperiodic.net/phil/prompt/</a></strong>\r
1858 </p>\r
1859 </dd>\r
1860 <dt>\r
1861 Adam's ZSH page\r
1862 </dt>\r
1863 <dd>\r
1864 <p>\r
1865     <strong><a href="http://www.adamspiers.org/computing/zsh/">http://www.adamspiers.org/computing/zsh/</a></strong>\r
1866 </p>\r
1867 </dd>\r
1868 <dt>\r
1869 Zzappers Best of ZSH Tips\r
1870 </dt>\r
1871 <dd>\r
1872 <p>\r
1873     <strong><a href="http://www.rayninfo.co.uk/tips/zshtips.html">http://www.rayninfo.co.uk/tips/zshtips.html</a></strong>\r
1874 </p>\r
1875 </dd>\r
1876 <dt>\r
1877 Zsh Webpage by Christian Schneider\r
1878 </dt>\r
1879 <dd>\r
1880 <p>\r
1881     <strong><a href="http://strcat.de/wiki/zsh/">http://strcat.de/wiki/zsh/</a></strong>\r
1882     <strong><a href="http://strcat.de/wiki/zsh-german">http://strcat.de/wiki/zsh-german</a></strong> (German translation. Help needed!)\r
1883 </p>\r
1884 </dd>\r
1885 <dt>\r
1886 The zsh-lovers webpage\r
1887 </dt>\r
1888 <dd>\r
1889 <p>\r
1890     <strong><a href="http://grml.org/zsh/">http://grml.org/zsh/</a></strong>\r
1891 </p>\r
1892 </dd>\r
1893 <dt>\r
1894 IRC channel\r
1895 </dt>\r
1896 <dd>\r
1897 <p>\r
1898     <strong>#zsh at irc.freenode.org</strong>\r
1899 </p>\r
1900 </dd>\r
1901 <dt>\r
1902 The Z shell reference-card (included in the zsh-lovers debian-package)\r
1903 </dt>\r
1904 <dd>\r
1905 <p>\r
1906     <strong><a href="http://www.bash2zsh.com/zsh_refcard/refcard.pdf">http://www.bash2zsh.com/zsh_refcard/refcard.pdf</a></strong>\r
1907 </p>\r
1908 </dd>\r
1909 </dl>\r
1910 </div>\r
1911 <h2>AUTHORS</h2>\r
1912 <div class="sectionbody">\r
1913 <p>This manpage was written by Michael Prokop, Christian <em>strcat</em>\r
1914 Schneider and Matthias Kopfermann. But many ideas have been taken from\r
1915 zsh-geeks e.g. from the zsh-mailinglists (zsh-users and zsh-workers),\r
1916 google, newsgroups and the zsh-Wiki.<br />\r
1917 Thanks for your cool and incredible tips. We learned much from you!</p>\r
1918 <p>In alphabetic order:</p>\r
1919 <div class="listingblock">\r
1920 <div class="content">\r
1921 <pre><tt>Andrew 'zefram' Main  - http://www.fysh.org/~zefram/\r
1922 Barton E. Schaefer    - http://www.well.com/user/barts/\r
1923 Matthias Kopfermann   - http://www.infodrom.north.de/~matthi/\r
1924 Oliver Kiddle         - http://people.freenet.de/opk/\r
1925 Paul Falstad          - http://www.falstad.com/\r
1926 Peter Stephenson      - http://homepage.ntlworld.com/p.w.stephenson/\r
1927 Richard Coleman\r
1928 Stephane Chazelas     - http://stephane.chazelas.free.fr/\r
1929 Sven Guckes           - http://www.guckes.net/\r
1930 Sven Wischnowsky      - http://w9y.de/zsh/zshrc</tt></pre>\r
1931 </div></div>\r
1932 </div>\r
1933 <h2>SEE ALSO</h2>\r
1934 <div class="sectionbody">\r
1935 <p>Manpages of zsh:</p>\r
1936 <div class="listingblock">\r
1937 <div class="content">\r
1938 <pre><tt>       zsh          Zsh overview\r
1939        zshall       Tthe Z shell meta-man page\r
1940        zshbuiltins  Zsh built-in commands\r
1941        zshcalsys    zsh calendar system\r
1942        zshcompctl   zsh programmable completion\r
1943        zshcompsys   Zsh completion system\r
1944        zshcompwid   Zsh completion widgets\r
1945        zshcontrib   User contributions to zsh\r
1946        zshexpn      Zsh expansion and substitution\r
1947        zshmisc      Anything not fitting into the other sections\r
1948        zshmodules   Zsh loadable modules\r
1949        zshoptions   Zsh options\r
1950        zshparam     Zsh parameters\r
1951        zshroadmap   Informal introduction to the zsh manual\r
1952        zshtcpsys    Zsh tcp system\r
1953        zshzle       Zsh command line editing\r
1954        zshzftpsys   Zsh built-in FTP client\r
1955        zshall       Meta-man page containing all of the above</tt></pre>\r
1956 </div></div>\r
1957 <p>Note: especially <em>man zshcontrib</em> covers very useful topics! <tt>\r
1958 Book: <strong>From Bash to Z Shell</strong> by Oliver Kiddle, Jerry Peck and Peter\r
1959 Stephenson. <strong>ISBN: 1590593766</strong>. - <strong><a href="http://www.bash2zsh.com/">bash2zsh.com</a></strong> </tt>\r
1960 Also take a look at the section <strong>LINKS</strong> in this manpage.</p>\r
1961 </div>\r
1962 <h2>BUGS</h2>\r
1963 <div class="sectionbody">\r
1964 <p>Probably. This manpage might be never complete. So please report bugs,\r
1965 feedback and suggestions to &lt;zsh-lovers@michael-prokop.at&gt;. Thank\r
1966 you!</p>\r
1967 </div>\r
1968 <h2>COPYRIGHT</h2>\r
1969 <div class="sectionbody">\r
1970 <p>Copyright  (C) Michael Prokop, Christian Schneider and Matthias\r
1971 Kopfermann.</p>\r
1972 </div>\r
1973 <div id="footer">\r
1974 <div id="footer-text">\r
1975 Last updated 01-Nov-2009 04:31:39 CEST\r
1976 </div>\r
1977 </div>\r
1978 </body>\r
1979 </html>\r