initial checkin
[zsh-lovers.git] / zsh-lovers.html
1 <!-- Creator     : groff version 1.18.1 -->
2 <!-- CreationDate: Sun Jun 19 12:12:12 2005 -->
3 <html>
4 <head>
5 <meta name="generator" content="groff -Thtml, see www.gnu.org">
6 <meta name="Content-Style" content="text/css">
7 <title>zsh&minus;lovers</title>
8 </head>
9 <body>
10
11 <h1 align=center>zsh&minus;lovers</h1>
12 <a href="#NAME">NAME</a><br>
13 <a href="#OVERVIEW">OVERVIEW</a><br>
14 <a href="#EXAMPLES">EXAMPLES</a><br>
15 <a href="#OPTIONS">OPTIONS</a><br>
16 <a href="#LINKS">LINKS</a><br>
17 <a href="#AUTHORS">AUTHORS</a><br>
18 <a href="#SEE ALSO">SEE ALSO</a><br>
19 <a href="#BUGS">BUGS</a><br>
20 <a href="#COPYRIGHT">COPYRIGHT</a><br>
21
22 <hr>
23 <a name="NAME"></a>
24 <h2>NAME</h2>
25 <!-- INDENTATION -->
26 <table width="100%" border=0 rules="none" frame="void"
27        cols="2" cellspacing="0" cellpadding="0">
28 <tr valign="top" align="left">
29 <td width="10%"></td>
30 <td width="89%">
31 <p>zsh&minus;lovers &minus; tips, tricks and examples for
32 the Z shell</p>
33 </td>
34 </table>
35 <a name="OVERVIEW"></a>
36 <h2>OVERVIEW</h2>
37 <!-- INDENTATION -->
38 <table width="100%" border=0 rules="none" frame="void"
39        cols="2" cellspacing="0" cellpadding="0">
40 <tr valign="top" align="left">
41 <td width="10%"></td>
42 <td width="89%">
43 <p>Whenever we look at the zsh manual we wonder why there
44 are no examples for those simply things in (shell) life. The
45 zsh contains many features, but there was no manpage with
46 some examples (like procmailex(5)). That&rsquo;s why we
47 wrote this manpage.</p>
48 <!-- INDENTATION -->
49 <p>Most of the tricks and oneliner come from the
50 mailinglists zsh&minus;users, zsh&minus;workers, google,
51 newsgroups and from ourself. See section <b>LINKS</b> for
52 details.</p>
53 <!-- INDENTATION -->
54 <p><b>Note:</b> This manpage (zsh-lovers(1)) is <b>not</b>
55 an offical part of the Z shell! It&rsquo;s just a just for
56 fun &minus; manpage ;) For comments, bugreports and feedback
57 take a quick look at the section <b>BUGS.</b></p>
58 </td>
59 </table>
60 <a name="EXAMPLES"></a>
61 <h2>EXAMPLES</h2>
62 <!-- INDENTATION -->
63 <table width="100%" border=0 rules="none" frame="void"
64        cols="2" cellspacing="0" cellpadding="0">
65 <tr valign="top" align="left">
66 <td width="4%"></td>
67 <td width="95%">
68 <p><b>REDIRECTION</b></p></td>
69 </table>
70 <!-- INDENTATION -->
71 <table width="100%" border=0 rules="none" frame="void"
72        cols="2" cellspacing="0" cellpadding="0">
73 <tr valign="top" align="left">
74 <td width="10%"></td>
75 <td width="89%">
76 <p>See also <i>man 1 zshmisc</i>.</p>
77 <!-- INDENTATION -->
78 <p>null command shorthands:</p>
79 <!-- INDENTATION -->
80 <pre> &quot;&lt; file&quot; is like &quot;$READNULLCMD &lt;file&quot;
81  &quot;&gt; file&quot; is like &quot;cat &gt;file&quot;
82  &quot;&gt;&gt; file&quot; is like &quot;cat &gt;&gt;file&quot;
83 </pre>
84 <!-- INDENTATION -->
85 <p>Append &lsquo;exit 1&rsquo; at the end of all *.sh
86 &minus; files:</p>
87 <!-- INDENTATION -->
88 <pre> $ echo &quot;exit 1&quot; &gt;&gt; *.sh
89 </pre>
90 <!-- INDENTATION -->
91 <p>Append /etc/services at the end of file &lsquo;foo&rsquo;
92 and &lsquo;bar&rsquo;:</p>
93 <!-- INDENTATION -->
94 <pre> $ cat /etc/services &gt;&gt; foo &gt;&gt; bar
95 </pre>
96 <!-- INDENTATION -->
97 <p>Pipe STDERR:</p>
98 <!-- INDENTATION -->
99 <pre> $ echo An error &gt;&amp;2 2&gt;&amp;1 | sed -e &rsquo;s/A/I/&rsquo;
100 </pre>
101 </td>
102 </table>
103 <!-- INDENTATION -->
104
105 <table width="100%" border=0 rules="none" frame="void"
106        cols="2" cellspacing="0" cellpadding="0">
107 <tr valign="top" align="left">
108 <td width="4%"></td>
109 <td width="95%">
110 <p><b>MULTIPLE I/O REDIRECTION</b></p></td>
111 </table>
112 <!-- INDENTATION -->
113 <table width="100%" border=0 rules="none" frame="void"
114        cols="2" cellspacing="0" cellpadding="0">
115 <tr valign="top" align="left">
116 <td width="10%"></td>
117 <td width="89%">
118 <p>Requires <i>setopt multios</i>! Some examples:</p>
119 <!-- INDENTATION -->
120 <p>Print output of &rsquo;ls&rsquo; into files
121 &rsquo;foo&rsquo; and &rsquo;bar&rsquo;:</p>
122 <!-- INDENTATION -->
123 <pre> $ ls &gt;foo &gt;bar
124 </pre>
125 <!-- INDENTATION -->
126 <p>Send standard output of one process to standard input of
127 several processes in the pipeline:</p>
128 <!-- INDENTATION -->
129 <pre> $ process1 &gt; &gt;(process1) &gt; &gt;(process2)
130 </pre>
131 <!-- INDENTATION -->
132 <p>Redirection to file as well as send on to pipe:</p>
133 <!-- INDENTATION -->
134 <pre> $ make install &gt; /tmp/logfile | grep -i error
135 </pre>
136 <!-- INDENTATION -->
137 <p>Redirect stderr to a command like xless without
138 redirecting stdout as well:</p>
139 <!-- INDENTATION -->
140 <pre> $ foo 2&gt;&gt;(xless)
141 ... but this executes the command asynchronously. To do it synchronously:
142  $ { { foo 1&gt;&amp;3 } 2&gt;&amp;1 | xless } 3&gt;&amp;1
143 </pre>
144 <!-- INDENTATION -->
145 <p>Redirect stderr two times:</p>
146 <!-- INDENTATION -->
147 <pre> $ setopt multios ; program 2&gt; file2 &gt; file1 2&gt;&amp;1
148 </pre>
149 <!-- INDENTATION -->
150 <p>More fun with stderr:</p>
151 <!-- INDENTATION -->
152 <pre> $ ./my-script.sh 2&gt; &gt;(grep -v geek &gt;error.log) | process-output &gt; output.log
153    echo &quot;Thats STDOUT&quot; &gt;&gt;(sed &rsquo;s/stdout/another example/&rsquo; &gt; foobar)
154 </pre>
155 </td>
156 </table>
157 <!-- INDENTATION -->
158
159 <table width="100%" border=0 rules="none" frame="void"
160        cols="2" cellspacing="0" cellpadding="0">
161 <tr valign="top" align="left">
162 <td width="4%"></td>
163 <td width="95%">
164 <p><b>MODIFIERS USAGE</b></p></td>
165 </table>
166 <!-- INDENTATION -->
167 <table width="100%" border=0 rules="none" frame="void"
168        cols="2" cellspacing="0" cellpadding="0">
169 <tr valign="top" align="left">
170 <td width="10%"></td>
171 <td width="89%">
172 <p>Modifiers are a powerful mechanism that lets you modify
173 the results returned by parameter, filename and history
174 expansion. See zshexpn(1) for details.</p>
175 <!-- INDENTATION -->
176 <p>Remove a trailing pathname component, leaving the head.
177 This works like &lsquo;dirname&rsquo;:</p>
178 <!-- INDENTATION -->
179 <pre>  $ echo =ls(:h)
180   /bin
181 </pre>
182 <!-- INDENTATION -->
183 <p>Remove all leading pathname components, leaving the tail.
184 This works like &lsquo;basename&rsquo;.</p>
185 <!-- INDENTATION -->
186 <pre>  $ echo =ls(:t)
187   ls
188 </pre>
189 <!-- INDENTATION -->
190 <p>Remove a filename extension of the form
191 &lsquo;.xxx&rsquo;, leaving the root name.</p>
192 <!-- INDENTATION -->
193 <pre>  $ echo $PWD
194   /usr/src/linux
195   $ echo $PWD:t
196   linux
197 </pre>
198 <!-- INDENTATION -->
199 <p>Remove all but the extension.</p>
200 <!-- INDENTATION -->
201 <pre>  $ foo=23.42
202   $ echo $foo
203   23.42
204   $ echo $foo:e
205   42
206 </pre>
207 <!-- INDENTATION -->
208 <p>Print the new command but do not execute it. Only works
209 with history expansion.</p>
210 <!-- INDENTATION -->
211 <pre>  $ echo =ls(:h)
212   /bin
213   $ !echo:p
214   $ echo =ls(:h)
215 </pre>
216 <!-- INDENTATION -->
217 <p>Quote the substituted words, escaping further
218 substitutions.</p>
219 <!-- INDENTATION -->
220 <pre>  $ bar=&quot;23&rsquo;42&quot;
221   $ echo $bar
222   23&rsquo;42
223   $ echo $bar:q
224   23&acute;42
225 </pre>
226 <!-- INDENTATION -->
227 <p>Convert the words to all lowercase.</p>
228 <!-- INDENTATION -->
229 <pre>  $ bar=FOOBAR
230   $ echo $bar
231   FOOBAR
232   $ echo $bar:l
233   foobar
234 </pre>
235 <!-- INDENTATION -->
236 <p>Convert the words to all uppercase.</p>
237 <!-- INDENTATION -->
238 <pre>  $ bar=foobar
239   $ echo $bar
240   foobar
241   $ echo $bar:u
242   FOOBAR
243 </pre>
244 <!-- INDENTATION -->
245 <p>Variables can be modified by modifiers, too. That makes
246 modification of variables possible without using any
247 external program.</p>
248 <!-- INDENTATION -->
249 <pre>  sentence=&quot;beginning and some words of a sentence with end.&quot;
250 </pre>
251 <!-- INDENTATION -->
252 <p>Now lets split this sentence-var by using the (s| |)
253 modifier which modifies words by splitting at &quot;
254 &quot;:</p>
255 <!-- INDENTATION -->
256 <pre>  words=${(s| |)sentence}
257   print $words[1] -&gt; &quot;beginning&quot;
258   print $words[-1] -&gt;&quot;end.&quot;
259 </pre>
260 <!-- INDENTATION -->
261 <p>Now if one wants to have the beginning of a sentence with
262 a Capital, it&rsquo;s as easy as doing:</p>
263 <!-- INDENTATION -->
264 <pre>  print &quot;${(C)words[1]} $words[2,-1]&quot;
265 </pre>
266 <!-- INDENTATION -->
267 <p>which capitalizes the first word of the list words and
268 then adds with &quot; &quot; second to last word of words.
269 It&rsquo;s possible to join these words as a colon separated
270 scalar.</p>
271 <!-- INDENTATION -->
272 <pre>  colonlist=${(j|,|)words} # (j|,|) joins with &quot;,&quot;.
273 </pre>
274 <!-- INDENTATION -->
275 <p>You can see that it&rsquo;s a scalar by testing with
276 (t):</p>
277 <!-- INDENTATION -->
278 <pre>  print ${(t)colonlist} prints &quot;scalar&quot;.
279   print ${(t)words} prints &quot;array&quot;.
280 </pre>
281 <!-- INDENTATION -->
282 <p>It&rsquo;s possible to sort arrays with o and O:</p>
283 <!-- INDENTATION -->
284 <pre>  print ${(o)words} # lists the words-array sorted (forwards)
285   print ${(O)words} # lists the words-array sorted (backwards)
286 </pre>
287 </td>
288 </table>
289 <!-- INDENTATION -->
290
291 <table width="100%" border=0 rules="none" frame="void"
292        cols="2" cellspacing="0" cellpadding="0">
293 <tr valign="top" align="left">
294 <td width="4%"></td>
295 <td width="95%">
296 <p><b>COMPLETITION</b></p></td>
297 </table>
298 <!-- INDENTATION -->
299 <table width="100%" border=0 rules="none" frame="void"
300        cols="2" cellspacing="0" cellpadding="0">
301 <tr valign="top" align="left">
302 <td width="10%"></td>
303 <td width="89%">
304 <p>See also <i>man 1 zshcompctl zshcompsys zshcompwid</i>.
305 zshcompctl is the old style of zsh programmable completion,
306 zshcompsys is the new completion system, zshcompwid are the
307 zsh completion widgets.</p>
308 <!-- INDENTATION -->
309 <p>Some functions, like _apt and _dpkg, are very slow. You
310 can use a cache in order to proxy the list of results (like
311 the list of available debian packages) Use a cache:</p>
312 <!-- INDENTATION -->
313 <pre> zstyle &rsquo;:completion:*&rsquo; use-cache on
314  zstyle &rsquo;:completion:*&rsquo; cache-path ~/.zsh/cache
315 </pre>
316 <!-- INDENTATION -->
317 <p>Prevent CVS files/directories from being completed :</p>
318 <!-- INDENTATION -->
319 <pre> zstyle &rsquo;:completion:*:(all-|)files&rsquo; ignored-patterns &rsquo;(|*/)CVS&rsquo;
320  zstyle &rsquo;:completion:*:cd:*&rsquo; ignored-patterns &rsquo;(*/)#CVS&rsquo;
321 </pre>
322 <!-- INDENTATION -->
323 <p>Fuzzy matching of completions for when you mistype
324 them:</p>
325 <!-- INDENTATION -->
326 <pre> zstyle &rsquo;:completion:*&rsquo; completer _complete _match _approximate
327  zstyle &rsquo;:completion:*:match:*&rsquo; original only
328  zstyle &rsquo;:completion:*:approximate:*&rsquo; max-errors 1 numeric
329 </pre>
330 <!-- INDENTATION -->
331 <p>And if you want the number of errors allowed by
332 _approximate to increase with the length of what you have
333 typed so far:</p>
334 <!-- INDENTATION -->
335 <pre> zstyle -e &rsquo;:completion:*:approximate:*&rsquo; max-errors &rsquo;reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )&rsquo;
336 </pre>
337 <!-- INDENTATION -->
338 <p>Ignore completion functions for commands you don&rsquo;t
339 have:</p>
340 <!-- INDENTATION -->
341 <pre> zstyle &rsquo;:completion:*:functions&rsquo; ignored-patterns &rsquo;_*&rsquo;
342 </pre>
343 <!-- INDENTATION -->
344 <p>With helper functions like:</p>
345 <!-- INDENTATION -->
346 <pre> xdvi() { command xdvi ${*:-*.dvi(om[1])} }
347 </pre>
348 <!-- INDENTATION -->
349 <p>you can avoid having to complete at all in many cases,
350 but if you do, you might want to fall into menu selection
351 immediately and to have the words sorted by time:</p>
352 <!-- INDENTATION -->
353 <pre> zstyle &rsquo;:completion:*:*:xdvi:*&rsquo; menu yes select
354  zstyle &rsquo;:completion:*:*:xdvi:*&rsquo; file-sort time
355 </pre>
356 <!-- INDENTATION -->
357 <p>Completing process IDs with menu selection:</p>
358 <!-- INDENTATION -->
359 <pre> zstyle &rsquo;:completion:*:*:kill:*&rsquo; menu yes select
360  zstyle &rsquo;:completion:*:kill:*&rsquo;   force-list always
361 </pre>
362 <!-- INDENTATION -->
363 <p>If you end up using a directory as argument, this will
364 remove the trailing slash (usefull in ln)</p>
365 <!-- INDENTATION -->
366 <pre> zstyle &rsquo;:completion:*&rsquo; squeeze-slashes true
367 </pre>
368 <!-- INDENTATION -->
369 <p>cd will never select the parent directory (e.g.: cd
370 ../&lt;TAB&gt;):</p>
371 <!-- INDENTATION -->
372 <pre> zstyle &rsquo;:completion:*:cd:*&rsquo; ignore-parents parent pwd
373 </pre>
374 </td>
375 </table>
376 <!-- INDENTATION -->
377
378 <table width="100%" border=0 rules="none" frame="void"
379        cols="2" cellspacing="0" cellpadding="0">
380 <tr valign="top" align="left">
381 <td width="4%"></td>
382 <td width="95%">
383 <p><b>ADVANCED GLOBBING</b></p></td>
384 </table>
385 <!-- INDENTATION -->
386 <table width="100%" border=0 rules="none" frame="void"
387        cols="2" cellspacing="0" cellpadding="0">
388 <tr valign="top" align="left">
389 <td width="10%"></td>
390 <td width="89%">
391 <p>See <i>man zshexpn | less -p &rsquo;Glob
392 Qualifiers&rsquo;</i></p>
393 <!-- INDENTATION -->
394 <p>List file &rsquo;foobar&rsquo; via recursiv search in
395 directories:</p>
396 <!-- INDENTATION -->
397 <pre> $ ls **/foobar
398 </pre>
399 <!-- INDENTATION -->
400 <p>List files file20, file30, file100, etc:</p>
401 <!-- INDENTATION -->
402 <pre> $ ls file&lt;20-&gt;
403 </pre>
404 <!-- INDENTATION -->
405 <p>List files with suffix c and pro (e.g. foo.c,
406 bar.pro):</p>
407 <!-- INDENTATION -->
408 <pre> $ ls *.(c|pro)
409 </pre>
410 <!-- INDENTATION -->
411 <p>List files which are word-readable:</p>
412 <!-- INDENTATION -->
413 <pre> $ ls *(R)
414 </pre>
415 <!-- INDENTATION -->
416 <p>List all .c-files except &rsquo;lex.c&rsquo;:</p>
417 <!-- INDENTATION -->
418 <pre> $ ls *.c~lex.c
419 </pre>
420 <!-- INDENTATION -->
421 <p>List all &lsquo;README&rsquo; - files case-insensitive
422 with max. one typo (e.g. RADME, REEME, RAEDME):</p>
423 <!-- INDENTATION -->
424 <pre> $ ls (#a1)README
425 </pre>
426 <!-- INDENTATION -->
427 <p>List files named README but accept one spelling error
428 including case-insensitive (e.g. RADME, REEME, RAEDME):</p>
429 <!-- INDENTATION -->
430 <pre> $ ls (#ia1)README
431 </pre>
432 <!-- INDENTATION -->
433 <p>List executable files, directories and symlinks:</p>
434 <!-- INDENTATION -->
435 <pre> $ ls *(*@)
436 </pre>
437 <!-- INDENTATION -->
438 <p>List dangling symlinks:</p>
439 <!-- INDENTATION -->
440 <pre> $ ls **/*(-@)
441 </pre>
442 <!-- INDENTATION -->
443 <p>List all zero-length-files which are not group- or
444 world-writable:</p>
445 <!-- INDENTATION -->
446 <pre> $ ls *(L0f.go-w.)
447 </pre>
448 <!-- INDENTATION -->
449 <p>List all .c-files for which there doesn&rsquo;t exist a
450 .o file:</p>
451 <!-- INDENTATION -->
452 <pre> $ c=(*.c) o=(*.o(N)) eval &rsquo;ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}&rsquo;
453 </pre>
454 <!-- INDENTATION -->
455 <p>Find (and print) all symbolic links without a target
456 within the current dirtree:</p>
457 <!-- INDENTATION -->
458 <pre> $ file **/*(D@) | fgrep broken
459  $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
460  $ echo **/*(@-^./=%p)
461  $ print -l **/*(-@)
462 </pre>
463 <!-- INDENTATION -->
464 <p>Rename all MP3-files from name with spaces.mp3 to Name
465 With Spaces.mp3:</p>
466 <!-- INDENTATION -->
467 <pre> $ for i in *.mp3; do
468           mv $i ${${(C)i}:s/Mp3/mp3/}
469    done
470 </pre>
471 <!-- INDENTATION -->
472 <p>Rename all PDF-files from name.mp3 to Name.mp3 (lowercase
473 to uppercase of first letter) without touching the rest of
474 the filename:</p>
475 <!-- INDENTATION -->
476 <pre> $ zmv &rsquo;([a-z])(*).pdf&rsquo; &rsquo;${(C)1}$2.pdf&rsquo;
477 </pre>
478 <!-- INDENTATION -->
479 <p>Substitutions in strings can be done by
480 string-indexes:</p>
481 <!-- INDENTATION -->
482 <pre> $ a=&quot;doh.&quot;;a[1]=&rsquo;d&rsquo;;a[-1]=&rsquo;. (Bart Simpson)&rsquo;
483  $ echo $a
484  doh. (Bart Simpson)
485 </pre>
486 <!-- INDENTATION -->
487 <p>Associative arrays:</p>
488 <!-- INDENTATION -->
489 <pre> $ typeset -A ass_array; ass_array=(one 1 two 2 three 3 four 4)
490  $ print ${(k)ass_array} # prints keys
491  one four two three
492  $ print ${(v)ass_array} # prints values
493  1 4 2 3
494  $ print $ass_array[one]
495  1
496 </pre>
497 <!-- INDENTATION -->
498 <p>Extract parts of a string. Print first word of output of
499 &rsquo;date&rsquo;:</p>
500 <!-- INDENTATION -->
501 <pre> $ print ${$( date )[1]}
502 </pre>
503 <!-- INDENTATION -->
504 <p>Extract parts of a string. Print ip-address of loopback
505 device:</p>
506 <!-- INDENTATION -->
507 <pre> $ print ${${$( LC_ALL=C /sbin/ifconfig lo )[6]}#addr:}
508 </pre>
509 <!-- INDENTATION -->
510 <p>Print specific line of a file. E.g. print line 5 of
511 file:</p>
512 <!-- INDENTATION -->
513 <pre> $ print -l ${&quot;$( &lt; file )&quot;[(f)5]}
514 </pre>
515 <!-- INDENTATION -->
516 <p>Print line containing string &rsquo;root&rsquo; of file
517 /etc/passwd:</p>
518 <!-- INDENTATION -->
519 <pre> $ print ${&quot;$( &lt; /etc/passwd )&quot;[(fr)*root*]}
520 </pre>
521 <!-- INDENTATION -->
522 <p>Print words two to four of output of
523 &rsquo;date&rsquo;:</p>
524 <!-- INDENTATION -->
525 <pre> $ print ${$( date )[2,4]}
526 </pre>
527 <!-- INDENTATION -->
528 <p>Use of two-dimensional indizes. Print time via date but
529 without seconds:</p>
530 <!-- INDENTATION -->
531 <pre> $ print ${$(date)[4][1,5]}
532 </pre>
533 <!-- INDENTATION -->
534 <p>Calculate floating point numbers:</p>
535 <!-- INDENTATION -->
536 <pre> $ printf &quot;%.0f0 $[ 2.8*15 ]
537 </pre>
538 <!-- INDENTATION -->
539 <p>Convert images from foo.gif to foo.png:</p>
540 <!-- INDENTATION -->
541 <pre> $ for i in **/*.gif; convert $i $i:r.png
542 </pre>
543 <!-- INDENTATION -->
544 <p>Download files created with LaTeX2HTML (e.g. the
545 ZSH-Guide):</p>
546 <!-- INDENTATION -->
547 <pre> $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
548      lynx -source $f &gt;${f:t}
549    done
550 </pre>
551 <!-- INDENTATION -->
552 <p>Make with dpkg a master-list of everyfile that it has
553 installed:</p>
554 <!-- INDENTATION -->
555 <pre> $ diff &lt;(find / | sort) &lt;(cat /var/lib/dpkg/info/*.list | sort)
556 </pre>
557 <!-- INDENTATION -->
558 <p>Replace this color escape-sequences:</p>
559 <!-- INDENTATION -->
560 <pre> $ autoload colors ; colors
561  $ print &quot;$bg[cyan]$fg[blue]Welcome to man zsh-lovers&quot; &gt;&gt; $TTY
562 </pre>
563 <!-- INDENTATION -->
564 <p>Get ASCII value of a character:</p>
565 <!-- INDENTATION -->
566 <pre> $ char=N ; print $((#char))
567 </pre>
568 <!-- INDENTATION -->
569 <p>Filename suffix. Note: (N) activates setopt nullglob only
570 for this loop.</p>
571 <!-- INDENTATION -->
572 <pre> $ for i in *.o(N); do
573           rm $i
574    done
575 </pre>
576 <!-- INDENTATION -->
577 <p>Rename files: &rsquo;FOO&rsquo; to &rsquo;foo&rsquo;:</p>
578 <!-- INDENTATION -->
579 <pre> $ for i in *(.); mv $i ${i:l}
580 </pre>
581 <!-- INDENTATION -->
582 <p>Rename files: &rsquo;bar&rsquo; to &rsquo;BAR&rsquo;:</p>
583 <!-- INDENTATION -->
584 <pre> $ for i in *(.); mv $i ${i:u}
585 </pre>
586 <!-- INDENTATION -->
587 <p>Show all suid-files in $PATH:</p>
588 <!-- INDENTATION -->
589 <pre> $ ls -latg ${(s.:.)PATH} | grep &rsquo;^...s&rsquo;
590 </pre>
591 </td>
592 </table>
593 <!-- INDENTATION -->
594
595 <table width="100%" border=0 rules="none" frame="void"
596        cols="2" cellspacing="0" cellpadding="0">
597 <tr valign="top" align="left">
598 <td width="4%"></td>
599 <td width="95%">
600 <p><b>ZMV - multiple move with zsh</b></p></td>
601 </table>
602 <!-- INDENTATION -->
603 <table width="100%" border=0 rules="none" frame="void"
604        cols="2" cellspacing="0" cellpadding="0">
605 <tr valign="top" align="left">
606 <td width="10%"></td>
607 <td width="89%">
608 <p>Requires &rsquo;autoload zmv&rsquo;. Some examples:</p>
609 <!-- INDENTATION -->
610 <p>Move serially all files (foo.foo &gt; 1.foo, fnord.foo
611 &gt; 2.foo, ..).</p>
612 <!-- INDENTATION -->
613 <pre> $ ls *
614  1.c  asd.foo  bla.foo  fnord.foo  foo.fnord  foo.foo
615  $ c=1 zmv &rsquo;*.foo&rsquo; &rsquo;$((c++)).foo&rsquo;
616  $ ls *
617  1.c  1.foo  2.foo  3.foo  4.foo  foo.fnord
618 </pre>
619 <!-- INDENTATION -->
620 <p>See above, but now only files with a filename &gt;= 30
621 chars.</p>
622 <!-- INDENTATION -->
623 <pre> $ c=1 zmv &quot;${(l:30-4::?:)}*.foo&quot; &rsquo;$((c++)).foo&rsquo;
624 </pre>
625 <!-- INDENTATION -->
626 <p>Replace spaces in filenames with a underline.</p>
627 <!-- INDENTATION -->
628 <pre> $ zmv &rsquo;* *&rsquo; &rsquo;$f:gs/ /_&rsquo;
629 </pre>
630 <!-- INDENTATION -->
631 <p>Change the suffix from *.sh to *.pl.</p>
632 <!-- INDENTATION -->
633 <pre> $ zmv -W &rsquo;*.sh&rsquo; &rsquo;*.pl&rsquo;
634 </pre>
635 <!-- INDENTATION -->
636 <p>Lowercase/uppercase all files and directories.</p>
637 <!-- INDENTATION -->
638 <pre> $ zmv &rsquo;(*)&rsquo; &rsquo;${(L)1}&rsquo; for lowercase
639  $ zmv &rsquo;(*)&rsquo; &rsquo;${(U)1}&rsquo; for uppercase
640 </pre>
641 <!-- INDENTATION -->
642 <p>Remove the suffix *.c from all c-files.</p>
643 <!-- INDENTATION -->
644 <pre> $ zmv &rsquo;(*).c&rsquo; &rsquo;$1&rsquo;
645 </pre>
646 <!-- INDENTATION -->
647 <p>Uppercase only the first letter of all *.mp3 - files.</p>
648 <!-- INDENTATION -->
649 <pre> $ zmv &rsquo;([a-z])(*).mp3&rsquo; &rsquo;${(C)1}$2.mp3&rsquo;
650 </pre>
651 <!-- INDENTATION -->
652 <p>Copy the target &lsquo;README&rsquo; in same directory as
653 each &lsquo;Makefile&rsquo;.</p>
654 <!-- INDENTATION -->
655 <pre> $ zmv -C &rsquo;(**/)Makefile&rsquo; &rsquo;${1}README&rsquo;
656 </pre>
657 <!-- INDENTATION -->
658 <p>Rename pic1.jpg, pic2.jpg,.. to pic0001.jpg,
659 pic0002.jpg,...</p>
660 <!-- INDENTATION -->
661 <pre> $ zmv &rsquo;pic(*).jpg&rsquo; &rsquo;pic${(l:4::0:)1}.jpg&rsquo;
662  $ zmv &rsquo;(**/)pic(*).jpg&rsquo; &rsquo;$1/pic${(l:4::0:)2}.jpg&rsquo; # recursive
663 </pre>
664 </td>
665 </table>
666 <!-- INDENTATION -->
667
668 <table width="100%" border=0 rules="none" frame="void"
669        cols="2" cellspacing="0" cellpadding="0">
670 <tr valign="top" align="left">
671 <td width="4%"></td>
672 <td width="95%">
673 <p><b>MODULES</b></p></td>
674 </table>
675 <!-- INDENTATION -->
676 <table width="100%" border=0 rules="none" frame="void"
677        cols="2" cellspacing="0" cellpadding="0">
678 <tr valign="top" align="left">
679 <td width="10%"></td>
680 <td width="89%">
681 <p>See also <i>man zshmodules</i>. Don&rsquo;t forget to run
682 <i>zmodload &minus;i MODULENAME</i> before using a module.
683 Example: <i>zmodload -i zsh/datetime</i>.</p>
684 </td>
685 </table>
686 <!-- INDENTATION -->
687 <table width="100%" border=0 rules="none" frame="void"
688        cols="2" cellspacing="0" cellpadding="0">
689 <tr valign="top" align="left">
690 <td width="10%"></td>
691 <td width="89%">
692 <p><b>zsh/cap</b></p></td>
693 </table>
694 <!-- INDENTATION -->
695 <table width="100%" border=0 rules="none" frame="void"
696        cols="2" cellspacing="0" cellpadding="0">
697 <tr valign="top" align="left">
698 <td width="21%"></td>
699 <td width="77%">
700 <p>Builtins for manipulating POSIX.1e (POSIX.6) capability
701 (privilege) sets.</p>
702 </td>
703 </table>
704 <!-- INDENTATION -->
705 <table width="100%" border=0 rules="none" frame="void"
706        cols="2" cellspacing="0" cellpadding="0">
707 <tr valign="top" align="left">
708 <td width="10%"></td>
709 <td width="89%">
710 <p><b>zsh/clone</b></p></td>
711 </table>
712 <!-- INDENTATION -->
713 <table width="100%" border=0 rules="none" frame="void"
714        cols="2" cellspacing="0" cellpadding="0">
715 <tr valign="top" align="left">
716 <td width="21%"></td>
717 <td width="77%">
718 <p>A builtin that can clone a running shell onto another
719 terminal.</p>
720 <!-- INDENTATION -->
721 <p>Creates a forked instance of the current shell ($! is set
722 to zero) and execute &lsquo;&lsquo;command&rsquo;&rsquo; on
723 /dev/tty8 (for this example):</p>
724 <!-- INDENTATION -->
725 <pre> $ zmodload zsh/clone
726  $ clone /dev/tty8 &amp;&amp; (($! == 0)) &amp;&amp; exec command
727 </pre>
728 </td>
729 </table>
730 <!-- INDENTATION -->
731
732 <table width="100%" border=0 rules="none" frame="void"
733        cols="2" cellspacing="0" cellpadding="0">
734 <tr valign="top" align="left">
735 <td width="10%"></td>
736 <td width="89%">
737 <p><b>zsh/compctl</b></p></td>
738 </table>
739 <!-- INDENTATION -->
740 <table width="100%" border=0 rules="none" frame="void"
741        cols="2" cellspacing="0" cellpadding="0">
742 <tr valign="top" align="left">
743 <td width="21%"></td>
744 <td width="77%">
745 <p>The <b>compctl</b> builtin for controlling
746 completion.</p>
747 </td>
748 </table>
749 <!-- INDENTATION -->
750 <table width="100%" border=0 rules="none" frame="void"
751        cols="2" cellspacing="0" cellpadding="0">
752 <tr valign="top" align="left">
753 <td width="10%"></td>
754 <td width="89%">
755 <p><b>zsh/complete</b></p></td>
756 </table>
757 <!-- INDENTATION -->
758 <table width="100%" border=0 rules="none" frame="void"
759        cols="2" cellspacing="0" cellpadding="0">
760 <tr valign="top" align="left">
761 <td width="21%"></td>
762 <td width="77%">
763 <p>The basic completion code.</p>
764 </td>
765 </table>
766 <!-- INDENTATION -->
767 <table width="100%" border=0 rules="none" frame="void"
768        cols="2" cellspacing="0" cellpadding="0">
769 <tr valign="top" align="left">
770 <td width="10%"></td>
771 <td width="89%">
772 <p><b>zsh/complist</b></p></td>
773 </table>
774 <!-- INDENTATION -->
775 <table width="100%" border=0 rules="none" frame="void"
776        cols="2" cellspacing="0" cellpadding="0">
777 <tr valign="top" align="left">
778 <td width="21%"></td>
779 <td width="77%">
780 <p>Completion listing extensions.</p>
781 </td>
782 </table>
783 <!-- INDENTATION -->
784 <table width="100%" border=0 rules="none" frame="void"
785        cols="2" cellspacing="0" cellpadding="0">
786 <tr valign="top" align="left">
787 <td width="10%"></td>
788 <td width="89%">
789 <p><b>zsh/computil</b></p></td>
790 </table>
791 <!-- INDENTATION -->
792 <table width="100%" border=0 rules="none" frame="void"
793        cols="2" cellspacing="0" cellpadding="0">
794 <tr valign="top" align="left">
795 <td width="21%"></td>
796 <td width="77%">
797 <p>A module with utility builtins needed for the shell
798 function based completion system.</p>
799 </td>
800 </table>
801 <!-- INDENTATION -->
802 <table width="100%" border=0 rules="none" frame="void"
803        cols="2" cellspacing="0" cellpadding="0">
804 <tr valign="top" align="left">
805 <td width="10%"></td>
806 <td width="89%">
807 <p><b>zsh/datetime</b></p></td>
808 </table>
809 <!-- INDENTATION -->
810 <table width="100%" border=0 rules="none" frame="void"
811        cols="2" cellspacing="0" cellpadding="0">
812 <tr valign="top" align="left">
813 <td width="21%"></td>
814 <td width="77%">
815 <p>Some date/time commands and parameters.</p>
816 <!-- INDENTATION -->
817 <p>Do not have GNU date? Let&rsquo;s replace it:</p>
818 <!-- INDENTATION -->
819 <pre> $ alias datereplacement=&rsquo;strftime &quot;%Y-%m-%d&quot; $EPOCHSECONDS&rsquo;
820  $ export DATE=&lsquo;datereplacement&lsquo;
821  $ echo $DATE
822 </pre>
823 </td>
824 </table>
825 <!-- INDENTATION -->
826
827 <table width="100%" border=0 rules="none" frame="void"
828        cols="2" cellspacing="0" cellpadding="0">
829 <tr valign="top" align="left">
830 <td width="10%"></td>
831 <td width="89%">
832 <p><b>zsh/deltochar</b></p></td>
833 </table>
834 <!-- INDENTATION -->
835 <table width="100%" border=0 rules="none" frame="void"
836        cols="2" cellspacing="0" cellpadding="0">
837 <tr valign="top" align="left">
838 <td width="21%"></td>
839 <td width="77%">
840 <p>A ZLE function duplicating EMACS&rsquo;
841 <b>zap&minus;to&minus;char</b>.</p>
842 </td>
843 </table>
844 <!-- INDENTATION -->
845 <table width="100%" border=0 rules="none" frame="void"
846        cols="2" cellspacing="0" cellpadding="0">
847 <tr valign="top" align="left">
848 <td width="10%"></td>
849 <td width="89%">
850 <p><b>zsh/example</b></p></td>
851 </table>
852 <!-- INDENTATION -->
853 <table width="100%" border=0 rules="none" frame="void"
854        cols="2" cellspacing="0" cellpadding="0">
855 <tr valign="top" align="left">
856 <td width="21%"></td>
857 <td width="77%">
858 <p>An example of how to write a module.</p>
859 </td>
860 </table>
861 <!-- INDENTATION -->
862 <table width="100%" border=0 rules="none" frame="void"
863        cols="2" cellspacing="0" cellpadding="0">
864 <tr valign="top" align="left">
865 <td width="10%"></td>
866 <td width="89%">
867 <p><b>zsh/files</b></p></td>
868 </table>
869 <!-- INDENTATION -->
870 <table width="100%" border=0 rules="none" frame="void"
871        cols="2" cellspacing="0" cellpadding="0">
872 <tr valign="top" align="left">
873 <td width="21%"></td>
874 <td width="77%">
875 <p>Some basic file manipulation commands as builtins.</p>
876 <!-- INDENTATION -->
877 <pre># search a directory for files containing a certain string then copy those files to another directory.
878   $ IFS=$&rsquo; &rsquo;
879   $ cp $(grep -lZr foobar .) otherdirectory
880 </pre>
881 </td>
882 </table>
883 <!-- INDENTATION -->
884
885 <table width="100%" border=0 rules="none" frame="void"
886        cols="2" cellspacing="0" cellpadding="0">
887 <tr valign="top" align="left">
888 <td width="10%"></td>
889 <td width="89%">
890 <p><b>zsh/mapfile</b></p></td>
891 </table>
892 <!-- INDENTATION -->
893 <table width="100%" border=0 rules="none" frame="void"
894        cols="2" cellspacing="0" cellpadding="0">
895 <tr valign="top" align="left">
896 <td width="21%"></td>
897 <td width="77%">
898 <p>Access to external files via a special associative
899 array.</p>
900 <!-- INDENTATION -->
901 <pre># grepping for two patterns
902   $ pattern1=&quot;foo&quot;
903   $ pattern2=&quot;bar foo&quot;
904   $ print -l ./**/*(DN.e{&rsquo;z=$mapfile[$REPLY] &amp;&amp;
905   [[ $z = *$pattern1* &amp;&amp; $z = *$pattern2* ]]&rsquo;})
906 # or a solution in combination with zsh/pcre
907   $ zmodload -i zsh/mapfile zsh/pcre
908   $ pattern1=&quot;foo&quot;
909   $ pattern2=&quot;bar foo&quot;
910   $ pcre_compile &quot;(?s)(?=.*?$pattern1).*?$pattern2&quot;
911   $ pcre_study
912   $ print -l ./**/*(DN.e{&rsquo;pcre_match $mapfile[$REPLY]&rsquo;})
913
914 # equivalent for &lsquo;&lsquo;less /etc/passwd | grep -v root&rsquo;&rsquo;
915   $ IFS=$&rsquo;0
916   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*root*}
917 # or - for case insensitive
918   $ setopt extendedglob
919   $ print -rl -- ${${=mapfile[/etc/passwd]}:#*(#i)root*}
920
921 # If a XML-file contains stuff like &lsquo;&lsquo;&lt;TAGA/&gt;&rsquo;&rsquo; and &lsquo;&lsquo;&lt;TAGB/&gt;&rsquo;&rsquo;, number this empty tags
922 # (ones ending in &rsquo;/&gt;&rsquo;) so if encountered in the same order, the preceeding tags would become
923 # &lsquo;&lsquo;&lt;TAGA/&gt;1&lt;/TAGA&gt;&rsquo;&rsquo; and &lsquo;&lsquo;&lt;TAGB/&gt;2&lt;/TAGB&gt;&rsquo;&rsquo;
924   $ cnt=0
925   $ apfile[data.xml.new]=${(S)mapfile[data.xml]//  &gt; (#im)&lt;TAGA&gt;*&lt;TAGA&gt;/&lt;TAGA&gt;$((++cnt))&lt;TAGA&gt;}
926
927 # removing all files in users Maildir/new that contain &lsquo;&lsquo;filename=&quot;gone.src&rsquo;&rsquo;
928   $ zmodload zsh/{files,mapfile}
929   $ rm -f /u1/??/*/Maildir/new/100*(.e{&rsquo;[[ $mapfile[$REPLY] == *filename=
930
931 # Grep out the Title from a postscript file and append that value to the end of
932 # the filename
933   $ autoload -U zmv
934   $ zmv &rsquo;(*).ps&rsquo; &rsquo;$1-${${${mapfile[$f]##*%%Title: }%% *}//[^a-zA-Z0-9_]/}.ps&rsquo;
935 </pre>
936 </td>
937 </table>
938 <!-- INDENTATION -->
939
940 <table width="100%" border=0 rules="none" frame="void"
941        cols="2" cellspacing="0" cellpadding="0">
942 <tr valign="top" align="left">
943 <td width="10%"></td>
944 <td width="89%">
945 <p><b>zsh/mathfunc</b></p></td>
946 </table>
947 <!-- INDENTATION -->
948 <table width="100%" border=0 rules="none" frame="void"
949        cols="2" cellspacing="0" cellpadding="0">
950 <tr valign="top" align="left">
951 <td width="21%"></td>
952 <td width="77%">
953 <p>Standard scientific functions for use in mathematical
954 evaluations.</p>
955 <!-- INDENTATION -->
956 <pre>$ echo $(( sin(1/4.0)**2 + cos(1/4.0)**2 - 1 ))
957   -1.1102230246251565e-16
958 $ echo $(( pi = 4.0 * atan(1.0) ))
959   3.1415926535897931
960 $ echo $(( f = sin(0.3) ))
961   0.29552020666133955
962 $ print $(( rand48(seed) ))
963   0.01043488334700271
964 </pre>
965 </td>
966 </table>
967 <!-- INDENTATION -->
968
969 <table width="100%" border=0 rules="none" frame="void"
970        cols="2" cellspacing="0" cellpadding="0">
971 <tr valign="top" align="left">
972 <td width="10%"></td>
973 <td width="89%">
974 <p><b>zsh/parameter</b></p></td>
975 </table>
976 <!-- INDENTATION -->
977 <table width="100%" border=0 rules="none" frame="void"
978        cols="2" cellspacing="0" cellpadding="0">
979 <tr valign="top" align="left">
980 <td width="21%"></td>
981 <td width="77%">
982 <p>Access to internal hash tables via special associative
983 arrays.</p>
984 </td>
985 </table>
986 <!-- INDENTATION -->
987 <table width="100%" border=0 rules="none" frame="void"
988        cols="2" cellspacing="0" cellpadding="0">
989 <tr valign="top" align="left">
990 <td width="10%"></td>
991 <td width="89%">
992 <p><b>zsh/pcre</b></p></td>
993 </table>
994 <!-- INDENTATION -->
995 <table width="100%" border=0 rules="none" frame="void"
996        cols="2" cellspacing="0" cellpadding="0">
997 <tr valign="top" align="left">
998 <td width="21%"></td>
999 <td width="77%">
1000 <p>Interface to the PCRE library.</p>
1001 <!-- INDENTATION -->
1002 <p>Important: requires zsh compiled with pcre-support. Check
1003 whether your version supports pcre via &lsquo;ldd =zsh |
1004 grep pcre&lsquo;. PCRE provides support for Perl&rsquo;s
1005 regular expressions (regex). You have to compile a regex and
1006 can match it afterwards using error codes:</p>
1007 <!-- INDENTATION -->
1008 <pre> $ zmodload zsh/pcre
1009  $ pcre_compile &rsquo;\s\d.\d{3}.\d{3} Euro&rsquo;  &amp;&amp;\
1010    pcre_match &rsquo; 1.000.000 Euro&rsquo; &amp;&amp;\
1011    echo &quot;matches&quot; || echo &quot;does not match&quot;
1012 </pre>
1013 <!-- INDENTATION -->
1014 <p>Note: if you are using complex regular expressions you
1015 can improve speed via pcre_study.</p>
1016 </td>
1017 </table>
1018 <!-- INDENTATION -->
1019 <table width="100%" border=0 rules="none" frame="void"
1020        cols="2" cellspacing="0" cellpadding="0">
1021 <tr valign="top" align="left">
1022 <td width="10%"></td>
1023 <td width="89%">
1024 <p><b>zsh/sched</b></p></td>
1025 </table>
1026 <!-- INDENTATION -->
1027 <table width="100%" border=0 rules="none" frame="void"
1028        cols="2" cellspacing="0" cellpadding="0">
1029 <tr valign="top" align="left">
1030 <td width="21%"></td>
1031 <td width="77%">
1032 <p>A builtin that provides a timed execution facility within
1033 the shell.</p>
1034 </td>
1035 </table>
1036 <!-- INDENTATION -->
1037 <table width="100%" border=0 rules="none" frame="void"
1038        cols="2" cellspacing="0" cellpadding="0">
1039 <tr valign="top" align="left">
1040 <td width="10%"></td>
1041 <td width="89%">
1042 <p><b>zsh/net/socket</b></p></td>
1043 </table>
1044 <!-- INDENTATION -->
1045 <table width="100%" border=0 rules="none" frame="void"
1046        cols="2" cellspacing="0" cellpadding="0">
1047 <tr valign="top" align="left">
1048 <td width="21%"></td>
1049 <td width="77%">
1050 <p>Manipulation of Unix domain sockets $ zmodload
1051 zsh/net/socket $ zsocket -l -d 3 #
1052 &lsquo;&lsquo;-l&rsquo;&rsquo;: open a socket listening on
1053 filename # &lsquo;&lsquo;-d&rsquo;&rsquo;: argument will be
1054 taken as the target file descriptor for the # connection #
1055 &lsquo;&lsquo;3&rsquo;&rsquo; : file descriptor. See
1056 &lsquo;&lsquo;A User&rsquo;s Guide to the
1057 Z-Shell&rsquo;&rsquo; # (3.7.2: File descriptors) $ zsocket
1058 -a -d 4 3 # &lsquo;&lsquo;-a&rsquo;&rsquo;: accept an
1059 incoming connection to the socket $ zsocket -a -d 5 3 #
1060 accept a connection $ echo foobar &gt;&amp;4 $ echo barfoo
1061 &gt;&amp;5 $ 4&gt;&amp;- 5&gt;&amp;- 3&gt;&amp;-</p>
1062 <!-- INDENTATION -->
1063 <p>In one shell:</p>
1064 <!-- INDENTATION -->
1065 <pre> $ zmodload zsh/net/socket
1066  $ zsocket -l -d 3 /tmp/mysocket # open listening socket
1067  $ zsocket -a -d 4 3             # accept a connection
1068  $ zsocket -a -d 5 3             # accept a connection
1069  $ echo Hi there &gt;&amp;4
1070  $ echo Hi there also &gt;&amp;5
1071  $ exec 4&gt;&amp;- 5&gt;&amp;- 3&gt;&amp;-
1072 </pre>
1073 <!-- INDENTATION -->
1074 <p>In another shell:</p>
1075 <!-- INDENTATION -->
1076 <pre> $ zmodload zsh/net/socket
1077  $ zsocket -d 3 /tmp/mysocket # connect to /tmp/socket
1078  $ zsocket -d 4 /tmp/mysocket # connect to /tmp/socket
1079  $ read msg &lt;&amp;3; echo got: &quot;$msg on fd 3&quot;
1080  $ read msg &lt;&amp;4; echo got: &quot;$msg on fd 4&quot;
1081  $ exec 3&gt;&amp;- 4&gt;&amp;-
1082 </pre>
1083 </td>
1084 </table>
1085 <!-- INDENTATION -->
1086
1087 <table width="100%" border=0 rules="none" frame="void"
1088        cols="2" cellspacing="0" cellpadding="0">
1089 <tr valign="top" align="left">
1090 <td width="10%"></td>
1091 <td width="89%">
1092 <p><b>zsh/stat</b></p></td>
1093 </table>
1094 <!-- INDENTATION -->
1095 <table width="100%" border=0 rules="none" frame="void"
1096        cols="2" cellspacing="0" cellpadding="0">
1097 <tr valign="top" align="left">
1098 <td width="21%"></td>
1099 <td width="77%">
1100 <p>A builtin command interface to the <b>stat</b> system
1101 call.</p>
1102 <!-- INDENTATION -->
1103 <p>Get size of a file in bytes:</p>
1104 <!-- INDENTATION -->
1105 <pre> $ zmodload -i zsh/stat
1106  $ stat -L +size file
1107 </pre>
1108 <!-- INDENTATION -->
1109 <p>Equal to GNU&rsquo;s:</p>
1110 <!-- INDENTATION -->
1111 <pre> $ stat -c %s file
1112 </pre>
1113 <!-- INDENTATION -->
1114 <p>Comparing file dates:</p>
1115 <!-- INDENTATION -->
1116 <pre>  $ file1=foo
1117   $ file2=bar
1118   $ touch bar &amp; sleep 5 &amp; touch foo
1119   $ echo $file1 is $(( $(stat +mtime $file2) - $(stat +mtime $file1) )) seconds older than $file2.
1120   bar is 5 seconds older than foo
1121 </pre>
1122 <!-- INDENTATION -->
1123 <p>List the files of a disk smaller than some other
1124 file:</p>
1125 <!-- INDENTATION -->
1126 <pre>  $ stat -A max +size some-other-file
1127   $ print -rl ./**/*(D.L-$max)
1128 </pre>
1129 <!-- INDENTATION -->
1130 <p>List the top 100 biggest files in a disk:</p>
1131 <!-- INDENTATION -->
1132 <pre>  $ ls -fld ./**/*(d&lsquo;stat +device .&lsquo;OL[1,100])
1133 </pre>
1134 <!-- INDENTATION -->
1135 <p>Get only the user name and the file names from (like ls
1136 -l * | awk &rsquo;{print $3&quot; &quot; $8}&rsquo;):</p>
1137 <!-- INDENTATION -->
1138 <pre>  $ for file; do
1139   &gt;   stat -sA user +uid -- &quot;$file&quot; &amp;&amp;
1140   &gt;     print -r -- &quot;$user&quot; &quot;$file&quot;
1141   &gt; done
1142 </pre>
1143 <!-- INDENTATION -->
1144 <p>Get the difference between actual bytes of file and
1145 allocated bytes of file:</p>
1146 <!-- INDENTATION -->
1147 <pre>  $ print $(($(stat +block -- file) * 512 - $(stat +size -- file)))
1148 </pre>
1149 <!-- INDENTATION -->
1150 <p>Find largest file:</p>
1151 <!-- INDENTATION -->
1152 <pre>  $ stat +size ./*(DOL[1])
1153   # &lsquo;&lsquo;D&rsquo;&rsquo;  : to include dot files (d lowercase is for device)
1154   # &lsquo;&lsquo;O&rsquo;&rsquo;  : reverse Ordered (o lowercase for non-reverse order)
1155   # &lsquo;&lsquo;L&rsquo;&rsquo;  : by file Length (l is for number of links)
1156   # &lsquo;&lsquo;[1]&rsquo;&rsquo;: return only first one
1157 </pre>
1158 <!-- INDENTATION -->
1159 <p>Delete files in a directory that hasn&rsquo;t been
1160 accessed in the last ten days and send ONE mail to the owner
1161 of the files informing him/her of the files&rsquo;
1162 deletion:</p>
1163 <!-- INDENTATION -->
1164 <pre>  $ zmodload zsh/stat zsh/files
1165   $ typeset -A f; f=()
1166   $ rm -f /path/**/*(.a+10e{&rsquo;stat -sA u +uidr $REPLY; f[$u]=&quot;$f[$u]$REPLY&quot;&rsquo;})
1167   $ for user (${(k)f}) {print -rn $f[$user]|mailx -s &quot;...&quot; $user}
1168 </pre>
1169 <!-- INDENTATION -->
1170 <p>Get a &quot;ls -l&quot; on all the files in the tree that
1171 are younger than a specified age:</p>
1172 <!-- INDENTATION -->
1173 <pre>  $ for d (. ./**/*(N/m-2))
1174   &gt;   print -r -- $&rsquo;0$d: &amp;&amp; cd $d &amp;&amp; {
1175   &gt;      for f (*(Nm-2om))
1176   &gt;   stat -F &rsquo;%b %d %H:%M&rsquo; -LsAs -- $f &amp;&amp;
1177   &gt;   print -r -- $s[3] ${(l:4:)s[4]} ${(l:8:)s[5]} \
1178   &gt;   ${(l:8:)s[6]} ${(l:8:)s[8]} $s[10] $f ${s[14]:+-&gt; $s[14]}
1179   &gt;   cd ~-
1180   &gt; }
1181 </pre>
1182 <!-- INDENTATION -->
1183 <p>Get file creation date:</p>
1184 <!-- INDENTATION -->
1185 <pre>  $ stat -F &rsquo;%d %m %Y&rsquo; +mtime ~/.zshrc
1186   30 06 2004
1187   $ stat -F &rsquo;%D&rsquo; +mtime ~/.zshrc
1188   06/30/04
1189 </pre>
1190 </td>
1191 </table>
1192 <!-- INDENTATION -->
1193
1194 <table width="100%" border=0 rules="none" frame="void"
1195        cols="2" cellspacing="0" cellpadding="0">
1196 <tr valign="top" align="left">
1197 <td width="10%"></td>
1198 <td width="89%">
1199 <p><b>zsh/system</b></p></td>
1200 </table>
1201 <!-- INDENTATION -->
1202 <table width="100%" border=0 rules="none" frame="void"
1203        cols="2" cellspacing="0" cellpadding="0">
1204 <tr valign="top" align="left">
1205 <td width="21%"></td>
1206 <td width="77%">
1207 <p>A builtin interface to various low&minus;level system
1208 features.</p>
1209 </td>
1210 </table>
1211 <!-- INDENTATION -->
1212 <table width="100%" border=0 rules="none" frame="void"
1213        cols="2" cellspacing="0" cellpadding="0">
1214 <tr valign="top" align="left">
1215 <td width="10%"></td>
1216 <td width="89%">
1217 <p><b>zsh/net/tcp</b></p></td>
1218 </table>
1219 <!-- INDENTATION -->
1220 <table width="100%" border=0 rules="none" frame="void"
1221        cols="2" cellspacing="0" cellpadding="0">
1222 <tr valign="top" align="left">
1223 <td width="21%"></td>
1224 <td width="77%">
1225 <p>Manipulation of TCP sockets</p>
1226 </td>
1227 </table>
1228 <!-- INDENTATION -->
1229 <table width="100%" border=0 rules="none" frame="void"
1230        cols="2" cellspacing="0" cellpadding="0">
1231 <tr valign="top" align="left">
1232 <td width="10%"></td>
1233 <td width="89%">
1234 <p><b>zsh/termcap</b></p></td>
1235 </table>
1236 <!-- INDENTATION -->
1237 <table width="100%" border=0 rules="none" frame="void"
1238        cols="2" cellspacing="0" cellpadding="0">
1239 <tr valign="top" align="left">
1240 <td width="21%"></td>
1241 <td width="77%">
1242 <p>Interface to the termcap database.</p>
1243 <!-- INDENTATION -->
1244 <pre> $ zmodload -ab zsh/termcap echotc
1245  $ GREEN=&lsquo;echotc AF 2&lsquo;
1246  $ YELLOW=&lsquo;echotc AF 3&lsquo;
1247  $ RED=&lsquo;echotc AF 1&lsquo;
1248  $ BRIGHTRED=&lsquo;echotc md ; echotc AF 1&lsquo;
1249  $ print -l ${GREEN}green ${YELLOW}yellow ${RED}red ${BRIGHTRED}brightred
1250 </pre>
1251 </td>
1252 </table>
1253 <!-- INDENTATION -->
1254
1255 <table width="100%" border=0 rules="none" frame="void"
1256        cols="2" cellspacing="0" cellpadding="0">
1257 <tr valign="top" align="left">
1258 <td width="10%"></td>
1259 <td width="89%">
1260 <p><b>zsh/terminfo</b></p></td>
1261 </table>
1262 <!-- INDENTATION -->
1263 <table width="100%" border=0 rules="none" frame="void"
1264        cols="2" cellspacing="0" cellpadding="0">
1265 <tr valign="top" align="left">
1266 <td width="21%"></td>
1267 <td width="77%">
1268 <p>Interface to the terminfo database.</p>
1269 </td>
1270 </table>
1271 <!-- INDENTATION -->
1272 <table width="100%" border=0 rules="none" frame="void"
1273        cols="2" cellspacing="0" cellpadding="0">
1274 <tr valign="top" align="left">
1275 <td width="10%"></td>
1276 <td width="89%">
1277 <p><b>zsh/zftp</b></p></td>
1278 </table>
1279 <!-- INDENTATION -->
1280 <table width="100%" border=0 rules="none" frame="void"
1281        cols="2" cellspacing="0" cellpadding="0">
1282 <tr valign="top" align="left">
1283 <td width="21%"></td>
1284 <td width="77%">
1285 <p>A builtin FTP client.</p>
1286 <!-- INDENTATION -->
1287 <p>Write ftp scripts as though shell:</p>
1288 <!-- INDENTATION -->
1289 <pre> $ init
1290  $ autoload -U zfinit &amp;&amp; zfinit
1291  $ zfparams www.example.invalid myuserid mypassword
1292  $ zfopen
1293  $ zfcd tips
1294  $ zfls -l zsh-lovers.html
1295  $ zfput zsh-lovers.html
1296  $ zfls -l zsh-lovers.html
1297 </pre>
1298 <!-- INDENTATION -->
1299 <p>Automatically transfer files using FTP with error
1300 checking:</p>
1301 <!-- INDENTATION -->
1302 <pre>  $ zftp open host.name.invalid user passwd || exit
1303   $ zftp get /remote/file &gt; /local/file; r=$?
1304   $ zftp close &amp;&amp; exit r
1305 </pre>
1306 <!-- INDENTATION -->
1307 <p>Compress and ftp on the fly:</p>
1308 <!-- INDENTATION -->
1309 <pre>  $ zftp open host.name.invalid user password
1310   $ zftp get $file | bzip2 &gt; ${file}.bz2
1311   $ zftp close
1312 </pre>
1313 <!-- INDENTATION -->
1314 <p>Long list of files on a ftp:</p>
1315 <!-- INDENTATION -->
1316 <pre>  $ autoload -U zfinit
1317   $ zfinit
1318   $ zfopen some-host
1319   $ zfcd /some/remote/Dir
1320   $ cd /some/local/Dir
1321 </pre>
1322 <!-- INDENTATION -->
1323 <p>If the list.txt is located on the remote host, change to
1324 $ zfget ${(f)&quot;$(zftp get
1325 /path/to/remote/list.txt)&quot;} $ zfget ${(f)&quot;$(cat
1326 list.txt)&quot;} $ zfclose</p>
1327 </td>
1328 </table>
1329 <!-- INDENTATION -->
1330 <table width="100%" border=0 rules="none" frame="void"
1331        cols="2" cellspacing="0" cellpadding="0">
1332 <tr valign="top" align="left">
1333 <td width="10%"></td>
1334 <td width="89%">
1335 <p><b>zsh/zle</b></p></td>
1336 </table>
1337 <!-- INDENTATION -->
1338 <table width="100%" border=0 rules="none" frame="void"
1339        cols="2" cellspacing="0" cellpadding="0">
1340 <tr valign="top" align="left">
1341 <td width="21%"></td>
1342 <td width="77%">
1343 <p>The Zsh Line Editor, including the <b>bindkey</b> and
1344 <b>vared</b> builtins.</p>
1345 </td>
1346 </table>
1347 <!-- INDENTATION -->
1348 <table width="100%" border=0 rules="none" frame="void"
1349        cols="2" cellspacing="0" cellpadding="0">
1350 <tr valign="top" align="left">
1351 <td width="10%"></td>
1352 <td width="89%">
1353 <p><b>zsh/zleparameter</b></p></td>
1354 </table>
1355 <!-- INDENTATION -->
1356 <table width="100%" border=0 rules="none" frame="void"
1357        cols="2" cellspacing="0" cellpadding="0">
1358 <tr valign="top" align="left">
1359 <td width="21%"></td>
1360 <td width="77%">
1361 <p>Access to internals of the Zsh Line Editor via
1362 parameters.</p>
1363 </td>
1364 </table>
1365 <!-- INDENTATION -->
1366 <table width="100%" border=0 rules="none" frame="void"
1367        cols="2" cellspacing="0" cellpadding="0">
1368 <tr valign="top" align="left">
1369 <td width="10%"></td>
1370 <td width="89%">
1371 <p><b>zsh/zprof</b></p></td>
1372 </table>
1373 <!-- INDENTATION -->
1374 <table width="100%" border=0 rules="none" frame="void"
1375        cols="2" cellspacing="0" cellpadding="0">
1376 <tr valign="top" align="left">
1377 <td width="21%"></td>
1378 <td width="77%">
1379 <p>A module allowing profiling for shell functions.</p>
1380 </td>
1381 </table>
1382 <!-- INDENTATION -->
1383 <table width="100%" border=0 rules="none" frame="void"
1384        cols="2" cellspacing="0" cellpadding="0">
1385 <tr valign="top" align="left">
1386 <td width="10%"></td>
1387 <td width="89%">
1388 <p><b>zsh/zpty</b></p></td>
1389 </table>
1390 <!-- INDENTATION -->
1391 <table width="100%" border=0 rules="none" frame="void"
1392        cols="2" cellspacing="0" cellpadding="0">
1393 <tr valign="top" align="left">
1394 <td width="21%"></td>
1395 <td width="77%">
1396 <p>A builtin for starting a command in a
1397 pseudo&minus;terminal.</p>
1398 <!-- INDENTATION -->
1399 <pre> $ zmodload -i zsh/zpty
1400  $ zpty PW passwd $1
1401  # &lsquo;&lsquo;-r&rsquo;&rsquo;: read the output of the command name.
1402  # &lsquo;&lsquo;z&rsquo;&rsquo; : Parameter
1403  $ zpty -r PW z &rsquo;*password:&rsquo;
1404  # send the to command name the given strings as input
1405  $ zpty -w PW $2
1406  $ zpty -r PW z &rsquo;*password:&rsquo;
1407  $ zpty -w PW $2
1408  # | The second form, with the -d option, is used to delete commands
1409  # | previously started, by supplying a list of their names. If no names
1410  # | are given, all commands are deleted. Deleting a command causes the HUP
1411  # | signal to be sent to the corresponding process.
1412  $ zpty -d PW
1413 </pre>
1414 </td>
1415 </table>
1416 <!-- INDENTATION -->
1417
1418 <table width="100%" border=0 rules="none" frame="void"
1419        cols="2" cellspacing="0" cellpadding="0">
1420 <tr valign="top" align="left">
1421 <td width="10%"></td>
1422 <td width="89%">
1423 <p><b>zsh/zselect</b></p></td>
1424 </table>
1425 <!-- INDENTATION -->
1426 <table width="100%" border=0 rules="none" frame="void"
1427        cols="2" cellspacing="0" cellpadding="0">
1428 <tr valign="top" align="left">
1429 <td width="21%"></td>
1430 <td width="77%">
1431 <p>Block and return when file descriptors are ready.</p>
1432 <!-- INDENTATION -->
1433 <pre># It&rsquo;s simular to
1434  ,----
1435  | $ sg=$(stty -g)
1436  | $ stty -icanon min 0 time 50
1437  | $ read yesno
1438  | $ stty &quot;$sg&quot;
1439  | $ case &quot;$yesno&quot; in
1440  | &gt;  yes) command1;;
1441  | &gt;  *) command2;;
1442  | &gt; esac
1443  &lsquo;----
1444 $ if zselect -t 500 -r 0 &amp;&amp; read yesno &amp;&amp; [ yes = &quot;$yesno&quot; ]; then
1445 &gt;    command1
1446 &gt; else
1447 &gt;    command1
1448 &gt; fi
1449 </pre>
1450 </td>
1451 </table>
1452 <!-- INDENTATION -->
1453
1454 <table width="100%" border=0 rules="none" frame="void"
1455        cols="2" cellspacing="0" cellpadding="0">
1456 <tr valign="top" align="left">
1457 <td width="10%"></td>
1458 <td width="89%">
1459 <p><b>zsh/zutil</b></p></td>
1460 </table>
1461 <!-- INDENTATION -->
1462 <table width="100%" border=0 rules="none" frame="void"
1463        cols="2" cellspacing="0" cellpadding="0">
1464 <tr valign="top" align="left">
1465 <td width="21%"></td>
1466 <td width="77%">
1467 <p>Some utility builtins, e.g. the one for supporting
1468 configuration via styles.</p></td>
1469 </table>
1470 <!-- INDENTATION -->
1471 <table width="100%" border=0 rules="none" frame="void"
1472        cols="2" cellspacing="0" cellpadding="0">
1473 <tr valign="top" align="left">
1474 <td width="4%"></td>
1475 <td width="95%">
1476 <p><b>SUBSTITUTION</b></p></td>
1477 </table>
1478 <!-- INDENTATION -->
1479 <table width="100%" border=0 rules="none" frame="void"
1480        cols="2" cellspacing="0" cellpadding="0">
1481 <tr valign="top" align="left">
1482 <td width="10%"></td>
1483 <td width="89%">
1484 <p>Path substitution:</p>
1485 <!-- INDENTATION -->
1486 <pre> $ ls -l =zsh  # is like: &rsquo;ls -l /path/to/zsh&rsquo; or &rsquo;ls -l &lsquo;which zsh&lsquo;&rsquo;
1487 </pre>
1488 <!-- INDENTATION -->
1489 <p>Process substitution:</p>
1490 <!-- INDENTATION -->
1491 <pre> $ (vi =(cmd)) # edit output of &rsquo;cmd&rsquo; (called process substitution).
1492 </pre>
1493 <!-- INDENTATION -->
1494 <p>Substitution of variables:</p>
1495 <!-- INDENTATION -->
1496 <pre> $ var1=42
1497  $ tmp=var1
1498  $ echo $((tmp))
1499  42
1500  $
1501
1502 $ var=foo
1503  $ tmp=var
1504  $ echo ${(P)tmp}
1505  foo
1506 </pre>
1507 </td>
1508 </table>
1509 <!-- INDENTATION -->
1510
1511 <table width="100%" border=0 rules="none" frame="void"
1512        cols="2" cellspacing="0" cellpadding="0">
1513 <tr valign="top" align="left">
1514 <td width="4%"></td>
1515 <td width="95%">
1516 <p><b>ALIASES</b></p></td>
1517 </table>
1518 <!-- INDENTATION -->
1519 <table width="100%" border=0 rules="none" frame="void"
1520        cols="2" cellspacing="0" cellpadding="0">
1521 <tr valign="top" align="left">
1522 <td width="10%"></td>
1523 <td width="89%">
1524 <p>Suffix aliases are supported in zsh since version 4.2.0.
1525 Some examples:</p>
1526 <!-- INDENTATION -->
1527 <pre> alias -s tex=vim
1528  alias -s html=w3m
1529  alias -s org=w3m
1530 </pre>
1531 </td>
1532 </table>
1533 <!-- INDENTATION -->
1534
1535 <table width="100%" border=0 rules="none" frame="void"
1536        cols="2" cellspacing="0" cellpadding="0">
1537 <tr valign="top" align="left">
1538 <td width="20%"></td>
1539 <td width="79%">
1540 <p>Now pressing return-key after entering
1541 &rsquo;foobar.vim&rsquo; starts vim with foobar.vim. Calling
1542 a html-file runs browser w3m. &rsquo;www.zsh.org&rsquo; and
1543 pressing enter starts w3m with argument
1544 www.zsh.org.</p></td>
1545 </table>
1546 <!-- INDENTATION -->
1547 <table width="100%" border=0 rules="none" frame="void"
1548        cols="2" cellspacing="0" cellpadding="0">
1549 <tr valign="top" align="left">
1550 <td width="10%"></td>
1551 <td width="89%">
1552 <p>Global aliases can be used anywhere in the command line.
1553 Example:</p>
1554 <!-- INDENTATION -->
1555 <pre> $ alias -g C=&rsquo;| wc -l&rsquo;
1556  $ grep alias ~/.zsh/* C
1557  443
1558 </pre>
1559 <!-- INDENTATION -->
1560 <p>Some more or less useful global aliases (choose whether
1561 they are useful or not for you on your own):</p>
1562 <!-- INDENTATION -->
1563 <pre> alias -g ...=&rsquo;../..&rsquo;
1564  alias -g ....=&rsquo;../../..&rsquo;
1565  alias -g .....=&rsquo;../../../..&rsquo;
1566  alias -g CA=&quot;2&gt;&amp;1 | cat -A&quot;
1567  alias -g C=&rsquo;| wc -l&rsquo;
1568  alias -g D=&quot;DISPLAY=:0.0&quot;
1569  alias -g DN=/dev/null
1570  alias -g ED=&quot;export DISPLAY=:0.0&quot;
1571  alias -g EG=&rsquo;|&amp; egrep&rsquo;
1572  alias -g EH=&rsquo;|&amp; head&rsquo;
1573  alias -g EL=&rsquo;|&amp; less&rsquo;
1574  alias -g ELS=&rsquo;|&amp; less -S&rsquo;
1575  alias -g ETL=&rsquo;|&amp; tail -20&rsquo;
1576  alias -g ET=&rsquo;|&amp; tail&rsquo;
1577  alias -g F=&rsquo; | fmt -&rsquo;
1578  alias -g G=&rsquo;| egrep&rsquo;
1579  alias -g H=&rsquo;| head&rsquo;
1580  alias -g HL=&rsquo;|&amp; head -20&rsquo;
1581  alias -g &sect;k=&quot;*~(*.bz2|*.gz|*.tgz|*.zip|*.z)&quot;
1582  alias -g LL=&quot;2&gt;&amp;1 | less&quot;
1583  alias -g L=&quot;| less&quot;
1584  alias -g LS=&rsquo;| less -S&rsquo;
1585  alias -g MM=&rsquo;| most&rsquo;
1586  alias -g M=&rsquo;| more&rsquo;
1587  alias -g NE=&quot;2&gt; /dev/null&quot;
1588  alias -g NS=&rsquo;| sort -n&rsquo;
1589  alias -g NUL=&quot;&gt; /dev/null 2&gt;&amp;1&quot;
1590  alias -g PIPE=&rsquo;|&rsquo;
1591  alias -g R=&rsquo; &gt; /c/aaa/tee.txt &rsquo;
1592  alias -g RNS=&rsquo;| sort -nr&rsquo;
1593  alias -g S=&rsquo;| sort&rsquo;
1594  alias -g TL=&rsquo;| tail -20&rsquo;
1595  alias -g T=&rsquo;| tail&rsquo;
1596  alias -g US=&rsquo;| sort -u&rsquo;
1597  alias -g VM=/var/log/messages
1598  alias -g X0G=&rsquo;| xargs -0 egrep&rsquo;
1599  alias -g X0=&rsquo;| xargs -0&rsquo;
1600  alias -g XG=&rsquo;| xargs egrep&rsquo;
1601  alias -g X=&rsquo;| xargs&rsquo;
1602 </pre>
1603 <!-- INDENTATION -->
1604 <p>Array parameters [array_name=(value1 value2 ...
1605 valueN)].</p>
1606 <!-- INDENTATION -->
1607 <pre> $ stupid=emacs
1608  $ echo $stupid[3]
1609  a
1610  $
1611 </pre>
1612 </td>
1613 </table>
1614 <!-- INDENTATION -->
1615
1616 <table width="100%" border=0 rules="none" frame="void"
1617        cols="2" cellspacing="0" cellpadding="0">
1618 <tr valign="top" align="left">
1619 <td width="4%"></td>
1620 <td width="95%">
1621 <p><b>SHELL-SCRIPTING</b></p></td>
1622 </table>
1623 <!-- INDENTATION -->
1624 <table width="100%" border=0 rules="none" frame="void"
1625        cols="2" cellspacing="0" cellpadding="0">
1626 <tr valign="top" align="left">
1627 <td width="10%"></td>
1628 <td width="89%">
1629 <p>This section provides some examples for often needed
1630 shellscript-stuff. Notice that you should not use otherwise
1631 most examples won&rsquo;t work.</p>
1632 <!-- INDENTATION -->
1633 <p>Parse options in shellscripts. Example taken from ZWS by
1634 Adam Chodorowski
1635 (http://www.chodorowski.com/projects/zws/):</p>
1636 <!-- INDENTATION -->
1637 <pre>parse_options()
1638 {
1639     o_port=(-p 9999)
1640     o_root=(-r WWW)
1641     o_log=(-d ZWS.log)
1642
1643    zparseopts -K -- p:=o_port r:=o_root h=o_help
1644     if [[ $? != 0 || &quot;$o_help&quot; != &quot;&quot; ]]; then
1645         echo Usage: $(basename &quot;$0&quot;) &quot;[-p PORT] [-r DIRECTORY]&quot;
1646         exit 1
1647     fi
1648
1649    port=$o_port[2]
1650     root=$o_root[2]
1651     log=$o_log[2]
1652
1653    if [[ $root[1] != &rsquo;/&rsquo; ]]; then root=&quot;$PWD/$root&quot;; fi
1654 }
1655 # now use the function:
1656 parse_options $*
1657 </pre>
1658 </td>
1659 </table>
1660 <!-- INDENTATION -->
1661
1662 <table width="100%" border=0 rules="none" frame="void"
1663        cols="2" cellspacing="0" cellpadding="0">
1664 <tr valign="top" align="left">
1665 <td width="4%"></td>
1666 <td width="95%">
1667 <p><b>MISC&minus;EXAMPLES</b></p></td>
1668 </table>
1669 <!-- INDENTATION -->
1670 <table width="100%" border=0 rules="none" frame="void"
1671        cols="2" cellspacing="0" cellpadding="0">
1672 <tr valign="top" align="left">
1673 <td width="10%"></td>
1674 <td width="89%">
1675 <p>Hint: A list of valid glob Qualifiers can be found in
1676 zshexpn(1). See &lsquo;&lsquo;man 1 zshexpn | less
1677 -p&rsquo;&rsquo; Qualifiers for details.</p>
1678 <!-- INDENTATION -->
1679 <p>Load all available modules at startup</p>
1680 <!-- INDENTATION -->
1681 <pre> $ typeset -U m
1682  $ m=()
1683  $ for md ($module_path) m=($m $md/**/*(*e:&rsquo;REPLY=${REPLY#$md/}&rsquo;::r))
1684  $ zmodload -i $m
1685 </pre>
1686 <!-- INDENTATION -->
1687 <p>Rename all MP3-Files from &lsquo;&lsquo;name with
1688 spaces.mp3&rsquo;&rsquo; to &lsquo;&lsquo;Name With
1689 Spaces.mp3&rsquo;&rsquo;:</p>
1690 <!-- INDENTATION -->
1691 <pre> $ for i in *.mp3; do
1692  &gt;     mv $i ${${(C)i}:s/Mp3/mp3/}
1693  &gt; done
1694 </pre>
1695 <!-- INDENTATION -->
1696 <p>Download with LaTeX2HTML created Files (for example the
1697 ZSH&minus;Guide):</p>
1698 <!-- INDENTATION -->
1699 <pre> $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
1700  &gt;     lynx -source $f &gt;${f:t}
1701  &gt; done
1702 </pre>
1703 <!-- INDENTATION -->
1704 <p>Replace the unreadable Escape-Sequences:</p>
1705 <!-- INDENTATION -->
1706 <pre> $ autoload colors ; colors
1707  $ print &quot;$bg[cyan]$fg[blue]You are an zsh user&quot; &gt;&gt; /dev/pts/3
1708 </pre>
1709 <!-- INDENTATION -->
1710 <p>Filename&minus;Expansion. <b>Note:</b> (N) activates
1711 setopt nullglob only for this loop.</p>
1712 <!-- INDENTATION -->
1713 <pre> $ for i in *.o(N); do
1714  &gt;     rm $i
1715  &gt; done
1716 </pre>
1717 <!-- INDENTATION -->
1718 <p>Re-linking broken links:</p>
1719 <!-- INDENTATION -->
1720 <pre> $ for f in ./**/*(-@); do
1721  &gt;     stat +link -A l $f
1722  &gt;     (cd $f:h &amp; [[ -e $l.gz ]]) &amp; ln -sf $l.gz $f
1723  &gt; done
1724 </pre>
1725 <!-- INDENTATION -->
1726 <p>Show me all the .c files for which there doesn&rsquo;t
1727 exist a .o file:</p>
1728 <!-- INDENTATION -->
1729 <pre>  $ c=(*.c) o=(*.o(N)) eval &rsquo;ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}&rsquo;
1730 </pre>
1731 <!-- INDENTATION -->
1732 <p>Load all available modules at startup:</p>
1733 <!-- INDENTATION -->
1734 <pre>  $ typeset -U m
1735   $ m=()
1736   $ for md ($module_path) m=($m $md/**/*(*e:&rsquo;REPLY=${REPLY#$md/}&rsquo;::r))
1737   $ zmodload -i $m
1738 </pre>
1739 <!-- INDENTATION -->
1740 <p>Rename all files within a directory such that their names
1741 get a numeral prefix in the default sort order:</p>
1742 <!-- INDENTATION -->
1743 <pre>  $ i=1; for j in *; do mv $j $i.$j; ((i++)); done
1744   $ i=1; for f in *; do mv $f $(echo $i| awk &rsquo;{ printf(&quot;%03d&quot;, $0)}&rsquo;).$f; ((i++)); done
1745   $ integer i=0; for f in *; do mv $f $[i+=1].$f; done
1746 </pre>
1747 <!-- INDENTATION -->
1748 <p>Find (and print) all symbolic links without a target
1749 within the current dirtree:</p>
1750 <!-- INDENTATION -->
1751 <pre>  $ $ file **/*(D@) | fgrep broken
1752   $ for i in **/*(D@); [[ -f $i || -d $i ]] || echo $i
1753   $ echo **/*(@-^./=%p)
1754   $ print -l **/*(-@)
1755 </pre>
1756 <!-- INDENTATION -->
1757 <p>List all plain files that do not have extensions listed
1758 in &lsquo;fignore&rsquo;:</p>
1759 <!-- INDENTATION -->
1760 <pre>  $ ls **/*~*(${~${(j/|/)fignore}})(.)
1761   # see above, but now omit executables
1762   $ ls **/*~*(${~${(j/|/)fignore}})(.^*)
1763 </pre>
1764 <!-- INDENTATION -->
1765 <p>Print out files that dont have extensions (require setopt
1766 extendedglob dotglob):</p>
1767 <!-- INDENTATION -->
1768 <pre>  $ printf &rsquo;%s0 ^?*.*
1769 </pre>
1770 <!-- INDENTATION -->
1771 <p>List files in reverse order sorted by name:</p>
1772 <!-- INDENTATION -->
1773 <pre>  $ print -rl -- *(On)
1774   or
1775   $ print -rl -- *(^on)
1776 </pre>
1777 <!-- INDENTATION -->
1778 <p>Synonymic to &lsquo;&lsquo;ps ax | awk &rsquo;{print
1779 $1}&rsquo;&rsquo;&rsquo;:</p>
1780 <!-- INDENTATION -->
1781 <pre>  $ print -l /proc/*/cwd(:h:t:s/self//)
1782 </pre>
1783 <!-- INDENTATION -->
1784 <p>Get the PID of a process (without
1785 &lsquo;&lsquo;ps&rsquo;&rsquo;,
1786 &lsquo;&lsquo;sed&rsquo;&rsquo;,
1787 &lsquo;&lsquo;pgrep&rsquo;&rsquo;, .. (under Linux):</p>
1788 <!-- INDENTATION -->
1789 <pre>  $ pid2 () {
1790   &gt;   local i
1791   &gt;   for i in /proc/&lt;-&gt;/stat
1792   &gt; do
1793   &gt;   [[ &quot;$(&lt; $i)&quot; = *\((${(j:|:)~@})\)* ]] &amp;&amp; echo $i:h:t
1794   &gt; done
1795   &gt; }
1796 </pre>
1797 <!-- INDENTATION -->
1798 <p>for X in &rsquo;n&rsquo; &rsquo;o&rsquo; &rsquo;p&rsquo;
1799 &rsquo;q&rsquo; &rsquo;r&rsquo; &rsquo;s&rsquo;
1800 &rsquo;t&rsquo; &rsquo;u&rsquo; &rsquo;v&rsquo;
1801 &rsquo;w&rsquo; &rsquo;x&rsquo; &rsquo;y&rsquo;; do ...:</p>
1802 <!-- INDENTATION -->
1803 <pre>  $ for (( i = 36#n; i &lt;= 36#y; i++ )); do
1804   &gt;   print ${$(([##36]i)):l}
1805   &gt; done
1806 # or in combination with &lsquo;&lsquo;dc&rsquo;&rsquo;
1807   $ print {$((##n))..$((##y))}P 10P | dc
1808 # or with &lsquo;&lsquo;eval&rsquo;&rsquo;
1809   $ eval print &rsquo;${$(([##36]&rsquo;{$((36#n))..$((36#y))}&rsquo;)):l}&rsquo;
1810 </pre>
1811 <!-- INDENTATION -->
1812 <p>Foreach in one line of shell:</p>
1813 <!-- INDENTATION -->
1814 <pre>  $ for f (*) print -r -- $f
1815 </pre>
1816 <!-- INDENTATION -->
1817 <p>Copy a directory recursively without data/files:</p>
1818 <!-- INDENTATION -->
1819 <pre>  $ dirs=(**/*(/))
1820   $ cd -- $dest_root
1821   $ mkdir -p -- $dirs
1822 # or without zsh
1823   $ find . -type d -exec env d=&quot;$dest_root&quot; sh -c &rsquo; exec mkdir -p -- &quot;$d/$1&quot;&rsquo; &rsquo;{}&rsquo; &rsquo;{}&rsquo; ;
1824 </pre>
1825 <!-- INDENTATION -->
1826 <p>If &lsquo;foo=23&rsquo;&rsquo;, then print with 10 digit
1827 with leading &rsquo;0&rsquo;:</p>
1828 <!-- INDENTATION -->
1829 <pre>  $ foo=23
1830   $ print ${(r:10::0:)foo}
1831 </pre>
1832 <!-- INDENTATION -->
1833 <p>Find the name of all the files in their home directory
1834 that have more than 20 characters in their file names:</p>
1835 <!-- INDENTATION -->
1836 <pre>  print -rl $HOME/${(l:20::?:)~:-}*
1837 </pre>
1838 <!-- INDENTATION -->
1839 <p>Save arrays:</p>
1840 <!-- INDENTATION -->
1841 <pre>  $ print -r -- ${(qq)m} &gt; $nameoffile      # save it
1842   $ eval &quot;m=($(cat -- $nameoffile)&quot;            # or use
1843   $ m=(&quot;${(@Q)${(z)&quot;$(cat -- $nameoffile)&quot;}}&quot;) # to restore it
1844 </pre>
1845 <!-- INDENTATION -->
1846 <p>Get a &quot;ls -l&quot; on all the files in the tree that
1847 are younger than a specified age (e.g &quot;ls -l&quot; all
1848 the files in the tree that where modified in the last 2
1849 days):</p>
1850 <!-- INDENTATION -->
1851 <pre>  $ ls -tld **/*(m-2)
1852 </pre>
1853 <!-- INDENTATION -->
1854 <p>This will give you a listing 1 file perl line (not
1855 &agrave; la ls -R). Think of an easy way to have a &quot;ls
1856 -R&quot; style output with only files newer than 2 day
1857 old.</p>
1858 <!-- INDENTATION -->
1859 <pre>  $ for d (. ./**/*(/)) {
1860   &gt;   print -r -- $&rsquo;0${d}:
1861   &gt;   cd $d &amp;&amp; {
1862   &gt;       l=(*(Nm-2))
1863   &gt;       (($#l)) &amp;&amp; ls -ltd -- $l
1864   &gt;       cd ~-
1865   &gt;   }
1866   &gt; }
1867 </pre>
1868 <!-- INDENTATION -->
1869 <p>If you also want directories to be included even if their
1870 mtime is more than 2 days old:</p>
1871 <!-- INDENTATION -->
1872 <pre>  $ for d (. ./**/*(/)) {
1873   &gt;   print -r -- $&rsquo;0${d}:
1874   &gt;   cd $d &amp;&amp; {
1875   &gt;      l=(*(N/,m-2))
1876   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l
1877   &gt;      cd ~-
1878   &gt;   }
1879   &gt; }
1880 </pre>
1881 <!-- INDENTATION -->
1882 <p>And if you want only the directories with mtime &lt; 2
1883 days to be listed:</p>
1884 <!-- INDENTATION -->
1885 <pre>  $ for d (. ./**/*(N/m-2)) {
1886   &gt;   print -r -- $&rsquo;0${d}:
1887   &gt;   cd $d &amp;&amp; {
1888   &gt;      l=(*(Nm-2))
1889   &gt;      (($#l)) &amp;&amp; ls -ltd -- $l
1890   &gt;      cd ~-
1891   &gt;   }
1892   &gt; }
1893 </pre>
1894 <!-- INDENTATION -->
1895 <p>Print 42 &lsquo;&lsquo;-&rsquo;&rsquo;:</p>
1896 <!-- INDENTATION -->
1897 <pre>  $ echo ${(l:42::-:)}
1898 # or use &lsquo;&lsquo;$COLUMS&rsquo;&rsquo;
1899   $ echo ${(l:$COLUMNS::-:)}
1900 # and now with colors (require autoload colors ;colors)
1901   $ echo &quot;$bg[red]$fg[black]${(l:42::-:)}&quot;
1902 </pre>
1903 <!-- INDENTATION -->
1904 <p>Redirect STDERR to a command like xless without
1905 redirecting STDOUT as well:</p>
1906 <!-- INDENTATION -->
1907 <pre>  $ foo 2&gt;&gt;(xless)
1908 # but this executes the command asynchronously. To do it synchronously:
1909   $ { { foo 1&gt;&amp;3 } 2&gt;&amp;1 | xless } 3&gt;&amp;1
1910 </pre>
1911 <!-- INDENTATION -->
1912 <p>Rename all MP3-Files from name with spaces.mp3 to Name
1913 With Spaces.mp3:</p>
1914 <!-- INDENTATION -->
1915 <pre>  $ for i in *.mp3; do
1916   &gt;     mv $i ${${(C)i}:s/Mp3/mp3/}
1917   &gt; done
1918 </pre>
1919 <!-- INDENTATION -->
1920 <p>Match file names containing only digits and ending with
1921 .xml (requiresetopt kshglob):</p>
1922 <!-- INDENTATION -->
1923 <pre>  $ ls -l [0-9]##.xml
1924   $ ls -l &lt;0-&gt;.xml
1925 </pre>
1926 <!-- INDENTATION -->
1927 <p>Remove all &quot;non txt&quot; files:</p>
1928 <!-- INDENTATION -->
1929 <pre>  $ rm ./^*.txt
1930 </pre>
1931 <!-- INDENTATION -->
1932 <p>Move 200 files from a directory into another:</p>
1933 <!-- INDENTATION -->
1934 <pre>  $ mv -- *([1,200]) /another/Dir
1935 </pre>
1936 <!-- INDENTATION -->
1937 <p>Convert images (foo.gif =&gt; foo.png):</p>
1938 <!-- INDENTATION -->
1939 <pre>  $ for i in **/*.gif; convert $i $i:r.png
1940 </pre>
1941 <!-- INDENTATION -->
1942 <p>Convert a collection of mp3 files to wave or cdr (e.g.
1943 file.wav -&gt; file.mp3):</p>
1944 <!-- INDENTATION -->
1945 <pre>  $ for i (./*.mp3){mpg321 --w - $i &gt; ${i:r}.wav}
1946 </pre>
1947 <!-- INDENTATION -->
1948 <p>Download with LaTeX2HTML created Files (for example the
1949 ZSH-Guide):</p>
1950 <!-- INDENTATION -->
1951 <pre>  $ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
1952   &gt;     lynx -source $f &gt;${f:t}
1953   &gt; done
1954 </pre>
1955 <!-- INDENTATION -->
1956 <p>Move all files in dir1 and dir2 that have line counts
1957 greater than 10 to another directory say
1958 &quot;/more10&quot;:</p>
1959 <!-- INDENTATION -->
1960 <pre>  $ mv dir[12]/**/*.cr(-.e{&rsquo;((&lsquo;wc -l &lt; $REPLY&lsquo; &gt; 10))&rsquo;}) /more10
1961 </pre>
1962 <!-- INDENTATION -->
1963 <p>Make with dpkg a master-list of everyfile that it has
1964 installed:</p>
1965 <!-- INDENTATION -->
1966 <pre>  $ diff &lt;(find / | sort) &lt;(cat /var/lib/dpkg/info/*.list | sort)
1967 </pre>
1968 <!-- INDENTATION -->
1969 <p>Replace the unreadable Escape-Sequences:</p>
1970 <!-- INDENTATION -->
1971 <pre>  $ autoload colors ; colors
1972   $ print &quot;$bg[cyan]$fg[blue]You are an zsh user&quot; &gt;&gt; /dev/pts/3
1973 </pre>
1974 <!-- INDENTATION -->
1975 <p>Get ASCII value of a character:</p>
1976 <!-- INDENTATION -->
1977 <pre>  $ char=N ; print $((#char))
1978 </pre>
1979 <!-- INDENTATION -->
1980 <p>Filename suffix: Note: The (N) says to use the nullglob
1981 option for this particular glob pattern.</p>
1982 <!-- INDENTATION -->
1983 <pre>  $ for i in *.o(N); do
1984   &gt;     rm $i
1985   &gt; done
1986 </pre>
1987 <!-- INDENTATION -->
1988 <p>Rename files; i. e. FOO to foo and bar to BAR:</p>
1989 <!-- INDENTATION -->
1990 <pre>  $ for i in *(.); mv $i ${i:l} # &lsquo;FOO&rsquo; to &lsquo;foo&rsquo;
1991   $ for i in *(.); mv $i ${i:u} # &lsquo;bar to &lsquo;BAR&rsquo;
1992 </pre>
1993 <!-- INDENTATION -->
1994 <p>Show all suid-files in $PATH:</p>
1995 <!-- INDENTATION -->
1996 <pre>  $ ls -latg ${(s.:.)PATH} | grep &rsquo;^...s&rsquo;
1997 # or more complex ;)
1998   $ print -l ${^path}/*(Ns,S)
1999 # or show only executables with a user given pattern
2000   $ print -l ${^path}/*vim*(*N)
2001 </pre>
2002 <!-- INDENTATION -->
2003 <p>gzip files when containing a certain string:</p>
2004 <!-- INDENTATION -->
2005 <pre>  $ gzip ${(ps: :)&quot;$(grep -lZ foobar ./*.txt(.))&quot;}
2006 </pre>
2007 <!-- INDENTATION -->
2008 <p>A small one-liner, that reads from stdin and prints to
2009 stdout the first unique line i. e. does not print lines that
2010 have been printed before (this is similar to the unique
2011 command, but unique can only handle adjacent lines):</p>
2012 <!-- INDENTATION -->
2013 <pre>  $ IFS=$&rsquo;0; print -rl -- ${(Oau)${(Oa)$(cat file;echo .)[1,-2]}}
2014 </pre>
2015 <!-- INDENTATION -->
2016 <p>Lists every executable in PATH:</p>
2017 <!-- INDENTATION -->
2018 <pre>  $ print -l ${^path}/*(-*N)
2019 </pre>
2020 <!-- INDENTATION -->
2021 <p>Match all .c files in all subdirectories, _except_ any
2022 SCCS subdirectories?</p>
2023 <!-- INDENTATION -->
2024 <pre>  $ ls **/*.c~(*/)#SCCS/*
2025 </pre>
2026 <!-- INDENTATION -->
2027 <p>List all &lsquo;README&rsquo; - files case-insensitive
2028 with max. one typo:</p>
2029 <!-- INDENTATION -->
2030 <pre>  $ ls **/*(#ia2)readme
2031 </pre>
2032 <!-- INDENTATION -->
2033 <p>Print version information of zsh:</p>
2034 <!-- INDENTATION -->
2035 <pre> $ print $ZSH_VERSION
2036 </pre>
2037 <!-- INDENTATION -->
2038 <p>Get hostspecific information:</p>
2039 <!-- INDENTATION -->
2040 <pre> $ echo $MACHTYPE $VENDOR $OSTYPE
2041 </pre>
2042 <!-- INDENTATION -->
2043 <p>Fast change of directories:</p>
2044 <!-- INDENTATION -->
2045 <pre> alias ...=&rsquo;cd ../..&rsquo;
2046  alias ....=&rsquo;cd ../../..&rsquo;
2047  alias .....=&rsquo;cd ../../../..&rsquo;
2048  alias ......=&rsquo;cd ../../../../..&rsquo;
2049  alias .......=&rsquo;cd ../../../../../..&rsquo;
2050 </pre>
2051 <!-- INDENTATION -->
2052 <p>Mailpath: simple multiple mailpath:</p>
2053 <!-- INDENTATION -->
2054 <pre>  mailpath=($HOME/Mail/mbox&rsquo;?new mail in mbox&rsquo;
2055             $HOME/Mail/tux.u-strasbg&rsquo;?new mail in tux&rsquo;
2056             $HOME/Mail/lilo&rsquo;?new mail in lilo&rsquo;
2057             $HOME/Mail/ldap-fr&rsquo;?new mail in ldap-fr&rsquo;)
2058 </pre>
2059 <!-- INDENTATION -->
2060 <p>Mailpath: dynamic mailpath:</p>
2061 <!-- INDENTATION -->
2062 <pre>  typeset -a mailpath
2063   for i in ~/Mail/Lists/*(.); do
2064      mailpath[$#mailpath+1]=&quot;${i}?You have new mail in ${i:t}.&quot;
2065   done
2066 </pre>
2067 <!-- INDENTATION -->
2068 <p>Avoid globbing on special commands:</p>
2069 <!-- INDENTATION -->
2070 <pre>for com in alias expr find mattrib mcopy mdir mdel which;
2071 alias $com=&quot;noglob $com&quot;
2072 </pre>
2073 <!-- INDENTATION -->
2074 <p>For migrating your bashprompt to zsh use the script
2075 bash2zshprompt located in the zsh source distribution under
2076 &rsquo;Misc&rsquo;.</p>
2077 <!-- INDENTATION -->
2078 <p>For migration from (t)csh to zsh use the c2z tool that
2079 converts csh aliases and environment and shell variables to
2080 zsh. It does this by running csh, and having csh report on
2081 aliases and variables. The script then converts these to zsh
2082 startup files. It has some issues and usage information that
2083 are documented at the top of this script.</p>
2084 <!-- INDENTATION -->
2085 <p>Here are functions to set the title and hardstatus of an
2086 <b>XTerm</b> or of <b>GNU Screen</b> to &rsquo;zsh&rsquo;
2087 and the current directory, respectively, when the prompt is
2088 displayed, and to the command name and rest of the command
2089 line, respectively, when a command is executed:</p>
2090 <!-- INDENTATION -->
2091 <pre>  function title {
2092       if [[ $TERM == &quot;screen&quot; ]]; then
2093         # Use these two for GNU Screen:
2094         print -nR $&rsquo; 33k&rsquo;$1$&rsquo; 33&rsquo;\
2095         print -nR $&rsquo; 33]0;&rsquo;$2$&rsquo;&rsquo;
2096       elif [[ $TERM == &quot;xterm&quot; || $TERM == &quot;rxvt&quot; ]]; then
2097         # Use this one instead for XTerms:
2098         print -nR $&rsquo; 33]0;&rsquo;$*$&rsquo;&rsquo;
2099       fi
2100   }
2101
2102  function precmd {
2103       title zsh &quot;$PWD&quot;
2104   }
2105
2106  function preexec {
2107       emulate -L zsh
2108       local -a cmd; cmd=(${(z)1})
2109       title $cmd[1]:t &quot;$cmd[2,-1]&quot;
2110   }
2111 </pre>
2112 <!-- INDENTATION -->
2113 <p>Put the following line into your ~/.screenrc to see this
2114 fancy hardstatus:</p>
2115 <!-- INDENTATION -->
2116 <pre>  caption always &quot;%3n %t%? (%u)%?%?: %h%?&quot;
2117 </pre>
2118 <!-- INDENTATION -->
2119 <p>Special variables which are assigned or you can
2120 assign:</p>
2121 <!-- INDENTATION -->
2122 <pre> $ echo $LINENO $RANDOM $SECONDS $COLUMNS $HISTCHARS
2123  $ echo $UID $EUID $GID $EGID $USERNAME
2124  $ echo $fignore $mailpath $cdpath
2125
2126 Show me all the .c files for which there doesn&rsquo;t exist a .o file:
2127  $ c=(*.c) o=(*.o(N)) eval &rsquo;ls ${${c:#(${~${(j:|:)${o:r}}}).c}:?done}&rsquo;
2128 </pre>
2129 <!-- INDENTATION -->
2130 <p>Find (and print) all symbolic links without a target
2131 within the current dirtree:</p>
2132 <!-- INDENTATION -->
2133 <pre> $ file **/*(D@) | fgrep broken
2134  $ for i in **/*(D@); [[ &minus;f $i || &minus;d $i ]] || echo $i
2135  $ echo **/*(@&minus;^./=%p)
2136  $ print &minus;l **/*(&minus;@)
2137 </pre>
2138 <!-- INDENTATION -->
2139 <p>Rename files; i. e. FOO to foo and bar to BAR:</p>
2140 <!-- INDENTATION -->
2141 <pre> $ for i in *(.); mv $i ${i:l} # &lsquo;FOO&rsquo; to &lsquo;foo&rsquo;
2142  $ for i in *(.); mv $i ${i:u} # &lsquo;bar to &lsquo;BAR&rsquo;
2143 </pre>
2144 <!-- INDENTATION -->
2145 <p>Show all suid-files in $PATH:</p>
2146 <!-- INDENTATION -->
2147 <pre> $ ls &minus;latg ${(s.:.)PATH} | grep &rsquo;^...s&rsquo;
2148 </pre>
2149 <!-- INDENTATION -->
2150 <p>List all &lsquo;README&rsquo; - files case-insensitive
2151 with max. one typo:</p>
2152 <!-- INDENTATION -->
2153 <pre> $ ls **/*(#ia2)readme
2154 </pre>
2155 </td>
2156 </table>
2157 <!-- INDENTATION -->
2158
2159 <table width="100%" border=0 rules="none" frame="void"
2160        cols="2" cellspacing="0" cellpadding="0">
2161 <tr valign="top" align="left">
2162 <td width="4%"></td>
2163 <td width="95%">
2164 <p><b>(RECURSIVE) GLOBBING&minus;EXAMPLES</b></p></td>
2165 </table>
2166 <!-- INDENTATION -->
2167 <table width="100%" border=0 rules="none" frame="void"
2168        cols="2" cellspacing="0" cellpadding="0">
2169 <tr valign="top" align="left">
2170 <td width="10%"></td>
2171 <td width="89%">
2172 <p>Search for &lsquo;README&rsquo; in all Subdirectories</p>
2173 <!-- INDENTATION -->
2174 <pre> $ print &minus;l **/README
2175 </pre>
2176 <!-- INDENTATION -->
2177 <p>Recursive &lsquo;&lsquo;chmod&rsquo;&rsquo;</p>
2178 <!-- INDENTATION -->
2179 <pre> $ chmod 700 **/(.) # Only files
2180  $ chmod 700 **/(/) # Only directories
2181 </pre>
2182 <!-- INDENTATION -->
2183 <p>List files beginning at &lsquo;foo23&rsquo; upwards
2184 (foo23, foo24, foo25, ..)</p>
2185 <!-- INDENTATION -->
2186 <pre> $ ls -l foo&lt;23&minus;&gt;
2187 </pre>
2188 <!-- INDENTATION -->
2189 <p>Remove spaces from filenames</p>
2190 <!-- INDENTATION -->
2191 <pre> $ for a in ./**/*\ *(Dod); do mv $a ${a:h}/${a:t:gs/ /_}; done
2192 </pre>
2193 <!-- INDENTATION -->
2194 <p>Show only all *.c and *.h - Files</p>
2195 <!-- INDENTATION -->
2196 <pre> $ ls -l *.(c|h)
2197 </pre>
2198 <!-- INDENTATION -->
2199 <p>Show <b>only</b> all *.c - files and ignore
2200 &lsquo;foo.c&rsquo;</p>
2201 <!-- INDENTATION -->
2202 <pre> $ ls *.c~foo.c
2203 </pre>
2204 <!-- INDENTATION -->
2205 <p>Show only world-readable files</p>
2206 <!-- INDENTATION -->
2207 <pre> $ ls -l *(R)
2208 </pre>
2209 <!-- INDENTATION -->
2210 <p>find and delete the files which are older than a given
2211 parameter (seconds/minutes/hours)</p>
2212 <!-- INDENTATION -->
2213 <pre> # deletes all regular file in /Dir that are older than 3 hours
2214    $ rm -f /Dir/**/*(.mh+3)
2215  # # deletes all symlinks in /Dir that are older than 3 minutes
2216    $ rm -f /Dir/**/*(@mm+3)
2217  # deletes all non dirs in /Dir that are older than 30 seconds
2218    $ rm -f /Dir/**/*(ms+30^/)
2219  # deletes all files more than 6 hours old
2220    $ rm -f **/*(mh+6)
2221  # deletes all folders, sub-folders and files older than one hour
2222    $ rm ./**/*(.Dmh+1,.DL0)
2223  # removes all files but the ten newer ones (delete all but last 10 files in a directory)
2224   $ rm ./*(Om[1,-11])
2225
2226 Note: If you get a arg list too long, you use the builtin rm. For example:
2227   $ zmodload zsh/files ; rm -f **/*(mh+6)
2228   or use the zargs function:
2229   $ autoload zargs ; zargs **/*(mh+6) -- rm -f
2230 </pre>
2231 <!-- INDENTATION -->
2232 <p><b>Explanation:</b></p>
2233 <!-- INDENTATION -->
2234 <pre>   ./: to avoid problem with files starting with &quot;&minus;&quot;
2235   **/: recursively descend
2236    *.: any file
2237 (...): qualifiers:
2238 </pre>
2239 </td>
2240 </table>
2241 <!-- TABS -->
2242
2243 <table width="100%" border=0 rules="none" frame="void"
2244        cols="3" cellspacing="0" cellpadding="0">
2245 <tr valign="top" align="left">
2246 <td width="11%"></td>
2247 <td width="7%">
2248
2249 <p>(&lt;a&gt;,&lt;b&gt;): files of &lt;a&gt; type or
2250 &lt;b&gt; type</p>
2251 </td>
2252 <td width="80%">
2253 </td>
2254 <tr valign="top" align="left">
2255 <td width="11%"></td>
2256 <td width="7%">
2257
2258 <p>&lt;a&gt;:</p>
2259 </td>
2260 <td width="80%">
2261 </td>
2262 <tr valign="top" align="left">
2263 <td width="11%"></td>
2264 <td width="7%">
2265
2266 <p>.: regular files</p>
2267 </td>
2268 <td width="80%">
2269 </td>
2270 <tr valign="top" align="left">
2271 <td width="11%"></td>
2272 <td width="7%">
2273
2274 <p>D: including dot files</p>
2275 </td>
2276 <td width="80%">
2277 </td>
2278 <tr valign="top" align="left">
2279 <td width="11%"></td>
2280 <td width="7%">
2281
2282 <p>mh+1: whose [m]odification time, is more (+) than
2283 [1]</p>
2284 </td>
2285 <td width="80%">
2286 </td>
2287 <tr valign="top" align="left">
2288 <td width="11%"></td>
2289 <td width="7%">
2290
2291 <p>[h]our in the past.</p>
2292 </td>
2293 <td width="80%">
2294 </td>
2295 <tr valign="top" align="left">
2296 <td width="11%"></td>
2297 <td width="7%">
2298
2299 <p>&lt;b&gt;:</p>
2300 </td>
2301 <td width="80%">
2302 </td>
2303 <tr valign="top" align="left">
2304 <td width="11%"></td>
2305 <td width="7%">
2306
2307 <p>.: regular files</p>
2308 </td>
2309 <td width="80%">
2310 </td>
2311 <tr valign="top" align="left">
2312 <td width="11%"></td>
2313 <td width="7%">
2314
2315 <p>D: including dot files</p>
2316 </td>
2317 <td width="80%">
2318 </td>
2319 <tr valign="top" align="left">
2320 <td width="11%"></td>
2321 <td width="7%">
2322
2323 <p>L0: of 0 [L]ength.</p>
2324 </td>
2325 <td width="80%">
2326 </td>
2327 </table>
2328 <!-- INDENTATION -->
2329 <table width="100%" border=0 rules="none" frame="void"
2330        cols="2" cellspacing="0" cellpadding="0">
2331 <tr valign="top" align="left">
2332 <td width="10%"></td>
2333 <td width="89%">
2334 <p>If you want to remove empty directories afterwards:</p>
2335 <!-- INDENTATION -->
2336 <pre> # &lsquo;&lsquo;/&rsquo;&rsquo; matches only directories and &lsquo;&lsquo;od&rsquo;&rsquo; sorted in depth order (so
2337  # that dir/subdir is removed before directory).
2338  $ rmdir ./**/*(/od) 2&gt; /dev/null
2339 </pre>
2340 <!-- INDENTATION -->
2341 <p><b>Note:</b> If you get a arg list too long, you use the
2342 builtin rm. For example:</p>
2343 <!-- INDENTATION -->
2344 <pre> $ zmodload zsh/files ; rm -f **/*(mh+6)
2345 </pre>
2346 <!-- INDENTATION -->
2347 <p>or use the zargs function:</p>
2348 <!-- INDENTATION -->
2349 <pre> $ autoload zargs ; zargs **/*(mh+6) -- rm -f
2350 </pre>
2351 <!-- INDENTATION -->
2352 <p>Delete only the oldest file in a directory:</p>
2353 <!-- INDENTATION -->
2354 <pre> $ rm ./*filename*(Om[1])
2355 </pre>
2356 <!-- INDENTATION -->
2357 <p>Sort the output from &lsquo;ls &minus;l&rsquo; by file
2358 size:</p>
2359 <!-- INDENTATION -->
2360 <pre> $ ls -fld *(OL)
2361 </pre>
2362 <!-- INDENTATION -->
2363 <p>Find most recent file in a directory:</p>
2364 <!-- INDENTATION -->
2365 <pre> $ setopt dotglob ; print directory/**/*(om[1])
2366 </pre>
2367 <!-- INDENTATION -->
2368 <p>List the top 100 biggest files in a disk</p>
2369 <!-- INDENTATION -->
2370 <pre> $ zmodload &minus;i zsh/stat ; ls &minus;fld ./**/*(d&lsquo;stat +device .&lsquo;OL[1,100])
2371 </pre>
2372 <!-- INDENTATION -->
2373 <pre> $ ls *(L0f.go-w.)
2374 </pre>
2375 <!-- INDENTATION -->
2376 <p>Find all files without a valid owner:</p>
2377 <!-- INDENTATION -->
2378 <pre> $ chmod someuser /**/*(D^u:${(j.:u:.)${(f)&quot;$(&lt;/etc/passwd)&quot;}%%:*}:)
2379 </pre>
2380 <!-- INDENTATION -->
2381 <p>Show only files are owned from group
2382 &lsquo;users&rsquo;:</p>
2383 <!-- INDENTATION -->
2384 <pre> $ ls -l *(G[users])
2385 </pre>
2386 </td>
2387 </table>
2388 <!-- INDENTATION -->
2389
2390 <table width="100%" border=0 rules="none" frame="void"
2391        cols="2" cellspacing="0" cellpadding="0">
2392 <tr valign="top" align="left">
2393 <td width="4%"></td>
2394 <td width="95%">
2395 <p><b>ZMV&minus;EXAMPLES</b></p></td>
2396 </table>
2397 <!-- INDENTATION -->
2398 <table width="100%" border=0 rules="none" frame="void"
2399        cols="2" cellspacing="0" cellpadding="0">
2400 <tr valign="top" align="left">
2401 <td width="10%"></td>
2402 <td width="89%">
2403 <p><b>Note:</b> &lsquo;&lsquo;autoload zmv&rsquo;&rsquo;
2404 needed! See &lsquo;&lsquo;man zshcontrib | less -p
2405 zmv&rsquo;&rsquo; for more details.</p>
2406 <!-- INDENTATION -->
2407 <p>Serially all files (foo.foo &gt; 1.foo, fnord.foo &gt;
2408 2.foo, ..):</p>
2409 <!-- INDENTATION -->
2410 <pre> $ ls *
2411  1.c  asd.foo  bla.foo  fnord.foo  foo.fnord  foo.foo
2412  $ c=1 zmv &rsquo;*.foo&rsquo; &rsquo;$((c++)).foo&rsquo;
2413  $ ls *
2414  1.c  1.foo  2.foo  3.foo  4.foo  foo.fnord
2415 </pre>
2416 <!-- INDENTATION -->
2417 <p>See above, but now only files with a filename &gt;= 30
2418 chars:</p>
2419 <!-- INDENTATION -->
2420 <pre> $ c=1 zmv &quot;${(l:30-4::?:)}*.foo&quot; &rsquo;$((c++)).foo&rsquo;
2421 </pre>
2422 <!-- INDENTATION -->
2423 <p>Replace spaces in filenames with a underline:</p>
2424 <!-- INDENTATION -->
2425 <pre> $ zmv &rsquo;* *&rsquo; &rsquo;$f:gs/ /_&rsquo;
2426 </pre>
2427 <!-- INDENTATION -->
2428 <p>Change the suffix from *.sh to *.pl:</p>
2429 <!-- INDENTATION -->
2430 <pre> $ zmv -W &rsquo;*.sh&rsquo; &rsquo;*.pl&rsquo;
2431 </pre>
2432 <!-- INDENTATION -->
2433 <p>lowercase/uppercase all files/directories:</p>
2434 <!-- INDENTATION -->
2435 <pre> # lowercase
2436    $ zmv &rsquo;(*)&rsquo; &rsquo;${(L)1}&rsquo;
2437  # uppercase
2438    zmv &rsquo;(*)&rsquo; &rsquo;${(U)1}&rsquo;
2439 </pre>
2440 <!-- INDENTATION -->
2441 <p>Remove the suffix *.c from all C-Files:</p>
2442 <!-- INDENTATION -->
2443 <pre> $ zmv &rsquo;(*).c&rsquo; &rsquo;$1&rsquo;
2444 </pre>
2445 <!-- INDENTATION -->
2446 <p>Uppercase only the first letter of all *.mp3 - files:</p>
2447 <!-- INDENTATION -->
2448 <pre> $ zmv &rsquo;([a-z])(*).mp3&rsquo; &rsquo;${(C)1}$2.mp3&rsquo;
2449 </pre>
2450 <!-- INDENTATION -->
2451 <p>Copy the target &lsquo;README&rsquo; in same directory as
2452 each &lsquo;Makefile&rsquo;:</p>
2453 <!-- INDENTATION -->
2454 <pre> $ zmv -C &rsquo;(**/)Makefile&rsquo; &rsquo;${1}README&rsquo;
2455 </pre>
2456 <!-- INDENTATION -->
2457 <p>Removing single quote from filenames (recursive):</p>
2458 <!-- INDENTATION -->
2459 <pre>$ zmv -Q &quot;(**/)(*&rsquo;*)(D)&quot; &quot;\$1\${2//&rsquo;/}&quot;
2460 </pre>
2461 <!-- INDENTATION -->
2462 <p>Replace spaces with underscores in filenames
2463 (recursive):</p>
2464 <!-- INDENTATION -->
2465 <pre>$ zmv -Q &quot;(**/)(* *)(D)&quot; &quot;\$1\${2// /_}&quot;
2466 </pre>
2467 <!-- INDENTATION -->
2468 <p>Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg,
2469 pic0002.jpg, ..:</p>
2470 <!-- INDENTATION -->
2471 <pre> # Not recursively
2472    $ zmv &rsquo;pic(*).jpg&rsquo; &rsquo;pic${(l:4::0:)1}.jpg&rsquo;
2473  # Recursively
2474    $ zmv &rsquo;(**/)pic(*).jpg&rsquo; &rsquo;$1/pic${(l:4::0:)2}.jpg&rsquo;
2475 </pre>
2476 </td>
2477 </table>
2478 <!-- INDENTATION -->
2479
2480 <table width="100%" border=0 rules="none" frame="void"
2481        cols="2" cellspacing="0" cellpadding="0">
2482 <tr valign="top" align="left">
2483 <td width="4%"></td>
2484 <td width="95%">
2485 <p><b>TIPS BY ZZAPPER
2486 (http://www.rayninfo.co.uk/tips/zshtips.html)</b></p></td>
2487 </table>
2488 <!-- INDENTATION -->
2489 <table width="100%" border=0 rules="none" frame="void"
2490        cols="2" cellspacing="0" cellpadding="0">
2491 <tr valign="top" align="left">
2492 <td width="10%"></td>
2493 <td width="89%">
2494 <pre> !! #  last command
2495  !$ #  last argument
2496  !$:h (last argument, strip one level)
2497  !?echo
2498  vi !* (all parameters)
2499  vi !$ (last parameters)
2500  !42
2501  history
2502  ^fred^joe             # edit previous command replace fred by joe
2503  !42:p
2504  also use control-R
2505
2506 cmdy !?cmd1?:*&lt;TAB&gt;   #get parameters of a previous command
2507
2508 !:0 is the previous command name
2509  !^, !:2, !:3, ?, !$ are the arguments
2510  !* is all the arguments
2511  !-2, !-3, ? are earlier commands
2512  !-2^, !-2:2, !-2$, !-2*
2513
2514 cd !$:h  (remove file name)
2515  cat !!:t (only file name)
2516  print ${param:&amp;}   (last substitute)
2517
2518 # globbing modifiers
2519  # :r removes the suffix from the result,
2520  # :t takes away the directory part
2521  # . means must be regular files not directories etc
2522  # *(om[1]) picks most recently modified file
2523  # (.N) no warning message if any file absent
2524  print *(om[1])   # print the most recent file
2525  print *(.om[1])  # print the most recent file (not directory)
2526  ls -l *(Om[1])   # oldest file
2527  print *(om[1,5]) # print the 5 most recent files
2528  vi *(.om[1]^D)   # vi newest file ^D means switch off GLOB_DOTS
2529  ls -l *(m4)      # list files modified exactly 4 days ago
2530  ls -ltd *(mw3)   # list files 3 weeks old
2531  echo *(m-1)      # files modified today
2532  echo *(m0)       # files modified today
2533  rm *.{aux,dvi,log,toc}(.N) # rm latex temp files N means no error msg is any file absent
2534
2535 print *(n:t)     # order by name strip directory
2536  print **/*(On:t) # recursive reverse order by name, strip directory
2537  print *.c(:r)    # strip suffix
2538  ls **/*(.)       # only files no directories
2539  -ld *(/)      # list only directories
2540  FOO = (#i)foo ]]  # case insensitive matching
2541  #oddities
2542  fred=$((6**2 + 6)) # can do maths
2543  print ${#path}     # length of &quot;path&quot; array
2544  print ${#path[1]}  # length of first element in path array
2545  ls fred{joe,sid}.pl
2546  ls fred{09..13}.pl
2547
2548 # arrays
2549  array=(~/.zshenv ~/.zshrc ~/.zlogout)
2550  % print ${array:t}
2551  .zshenv .zshrc .zlogout
2552
2553 x=&quot;bu&amp;^*ck&quot;                  # variable with mucky characters
2554  print ${x//[^[:alnum:]]/_}   # replace all non-alphanumerics with _
2555
2556 cp file ~1                   # where 1 is first entry in pushd stack
2557  #zsh completion
2558  startfilename&lt;tab&gt;           # will complete matching files anywhere in $PATH
2559  startfilename&lt;C-D&gt;           # will list matching files anywhere in $PATH
2560  #directory sizes
2561  du -sk *(/)
2562
2563 ls * | grep foo | less
2564  #to
2565  ls * G foo L
2566  #
2567
2568 #magic equals
2569  vim =some_file                            # edits file anywhere in $PATH
2570  ls =some_file                             # lists file anywhere in $PATH
2571  #magic ** (recursion)
2572  vim **/some_file                          # edits file under under current dir
2573  # modifying more than one file (multios)
2574  # writes ls results to file1 &amp; file2 appends to filec
2575  ls &gt; file1 &gt; file2 &gt;&gt; file3 | wc
2576 </pre>
2577 <!-- INDENTATION -->
2578 <p>Find file containing string &rsquo;printf&rsquo; in
2579 /usr/include.</p>
2580 <!-- INDENTATION -->
2581 <pre> $ zargs /usr/include/**/*.h &minus;&minus; grep printf /dev/null
2582 </pre>
2583 <!-- INDENTATION -->
2584 <p>A solution without zsh could look like:</p>
2585 <!-- INDENTATION -->
2586 <pre> $ find /usr/include -name \*.h &minus;exec grep printf /dev/null {} ;
2587 </pre>
2588 <!-- INDENTATION -->
2589 <p>Create a directory structure based on an existing
2590 one.</p>
2591 <!-- INDENTATION -->
2592 <pre> $ dirs=(**/*(/))
2593  $ cd &minus;&minus; $dest_root
2594  $ mkdir &minus;p &minus;&minus; $dirs
2595 </pre>
2596 <!-- INDENTATION -->
2597 <p>A solution without zsh could look like:</p>
2598 <!-- INDENTATION -->
2599 <pre> $ src=/usr/local
2600  $ dst=/opt
2601  $ cd &quot;$src&quot;
2602  $ find . -type d | cpio -pdmv &quot;$dst&quot;
2603 </pre>
2604 <!-- INDENTATION -->
2605 <p>Uncompress file and read it</p>
2606 <!-- INDENTATION -->
2607 <pre>less &lt;(gzip -cd foo.gz)
2608 </pre>
2609 <!-- INDENTATION -->
2610 <p>A solution without zsh could look like:</p>
2611 <!-- INDENTATION -->
2612 <pre> $ gzip -cd foo.gz &amp;&amp; less foo
2613 </pre>
2614 <!-- INDENTATION -->
2615 <p>Print two files and sort them</p>
2616 <!-- INDENTATION -->
2617 <pre> $ sort &lt;f{oo,ubar}
2618 </pre>
2619 <!-- INDENTATION -->
2620 <p>A solution without zsh could look like:</p>
2621 <!-- INDENTATION -->
2622 <pre> $ cat foo fubar | sort
2623 </pre>
2624 <!-- INDENTATION -->
2625 <p>Find files up from current directory and change
2626 permissions to &rsquo;700&rsquo;.</p>
2627 <!-- INDENTATION -->
2628 <pre> $ chmod 700 **/*(.)
2629 </pre>
2630 <!-- INDENTATION -->
2631 <p>A solution without zsh could look like:</p>
2632 <!-- INDENTATION -->
2633 <pre> $ find . &minus;type f &minus;exec chmod 700 {} \;
2634 </pre>
2635 <!-- INDENTATION -->
2636 <p>List details of the executable &rsquo;foobar&rsquo;.</p>
2637 <!-- INDENTATION -->
2638 <pre> $ ls -l =foobar
2639 </pre>
2640 <!-- INDENTATION -->
2641 <p>A solution without zsh could look like:</p>
2642 <!-- INDENTATION -->
2643 <pre> $ ls -l &lsquo;which foobar&lsquo;
2644 </pre>
2645 <!-- INDENTATION -->
2646 <p>Small examples</p>
2647 <!-- INDENTATION -->
2648 <pre>&acute;cd old new&rsquo; replaces &rsquo;old&rsquo; with &rsquo;new&rsquo; in directory-names.
2649 &acute;which -a cmd&rsquo; lists all occurences of &rsquo;cmd&rsquo; in $PATH.
2650 </pre>
2651 </td>
2652 </table>
2653 <a name="OPTIONS"></a>
2654 <h2>OPTIONS</h2>
2655 <!-- INDENTATION -->
2656
2657 <table width="100%" border=0 rules="none" frame="void"
2658        cols="2" cellspacing="0" cellpadding="0">
2659 <tr valign="top" align="left">
2660 <td width="10%"></td>
2661 <td width="89%">
2662 <p>Navigation options</p></td>
2663 </table>
2664 <!-- INDENTATION -->
2665 <table width="100%" border=0 rules="none" frame="void"
2666        cols="2" cellspacing="0" cellpadding="0">
2667 <tr valign="top" align="left">
2668 <td width="21%"></td>
2669 <td width="77%">
2670 <p>auto_cd (allow one to change to a directory by entering
2671 it as a command). auto_pushd (automatically append dirs to
2672 the push/pop list) pushd_ignore_dups (and don&rsquo;t
2673 duplicate them)</p>
2674 </td>
2675 </table>
2676 <!-- TABS -->
2677 <table width="100%" border=0 rules="none" frame="void"
2678        cols="3" cellspacing="0" cellpadding="0">
2679 <tr valign="top" align="left">
2680 <td width="11%"></td>
2681 <td width="5%">
2682
2683 <p>Misc</p>
2684 </td>
2685 <td width="82%">
2686 </td>
2687 </table>
2688 <!-- INDENTATION -->
2689 <table width="100%" border=0 rules="none" frame="void"
2690        cols="2" cellspacing="0" cellpadding="0">
2691 <tr valign="top" align="left">
2692 <td width="10%"></td>
2693 <td width="89%">
2694 <p>no_hup (don&rsquo;t send HUP signal to background jobs
2695 when exiting ZSH) print_exit_value (show a message with the
2696 exit code when a command returns with a non-zero exit
2697 code)</p>
2698 </td>
2699 </table>
2700 <!-- INDENTATION -->
2701 <table width="100%" border=0 rules="none" frame="void"
2702        cols="2" cellspacing="0" cellpadding="0">
2703 <tr valign="top" align="left">
2704 <td width="10%"></td>
2705 <td width="89%">
2706 <p>History options</p></td>
2707 </table>
2708 <!-- INDENTATION -->
2709 <table width="100%" border=0 rules="none" frame="void"
2710        cols="2" cellspacing="0" cellpadding="0">
2711 <tr valign="top" align="left">
2712 <td width="21%"></td>
2713 <td width="77%">
2714 <p>hist_verify (let the user edit the command line after
2715 history expansion (e.g. !ls) instead of immediately running
2716 it)</p>
2717 <!-- INDENTATION -->
2718 <p>Use the same history file for all sessions :</p>
2719 <!-- INDENTATION -->
2720 <pre> setopt SHARE_HISTORY
2721 </pre>
2722 </td>
2723 </table>
2724 <!-- INDENTATION -->
2725
2726 <table width="100%" border=0 rules="none" frame="void"
2727        cols="2" cellspacing="0" cellpadding="0">
2728 <tr valign="top" align="left">
2729 <td width="10%"></td>
2730 <td width="89%">
2731 <p>Privacy / Security</p></td>
2732 </table>
2733 <!-- INDENTATION -->
2734 <table width="100%" border=0 rules="none" frame="void"
2735        cols="2" cellspacing="0" cellpadding="0">
2736 <tr valign="top" align="left">
2737 <td width="21%"></td>
2738 <td width="77%">
2739 <p>no_clobber (or set -C; prevent &rsquo;&gt;&rsquo;
2740 redirection from truncating the given file if it already
2741 exists)</p>
2742 </td>
2743 </table>
2744 <!-- INDENTATION -->
2745 <table width="100%" border=0 rules="none" frame="void"
2746        cols="2" cellspacing="0" cellpadding="0">
2747 <tr valign="top" align="left">
2748 <td width="10%"></td>
2749 <td width="89%">
2750 <p>Spelling correction</p></td>
2751 </table>
2752 <!-- INDENTATION -->
2753 <table width="100%" border=0 rules="none" frame="void"
2754        cols="2" cellspacing="0" cellpadding="0">
2755 <tr valign="top" align="left">
2756 <td width="21%"></td>
2757 <td width="77%">
2758 <p>correct (automatically correct the spelling of commands)
2759 correct_all (automatically correct the spelling of each word
2760 on the command line) dvorak (dvorak layout)</p>
2761 </td>
2762 </table>
2763 <a name="LINKS"></a>
2764 <h2>LINKS</h2>
2765 <!-- INDENTATION -->
2766 <table width="100%" border=0 rules="none" frame="void"
2767        cols="2" cellspacing="0" cellpadding="0">
2768 <tr valign="top" align="left">
2769 <td width="10%"></td>
2770 <td width="89%">
2771 <p>The Z shell Homepage</p></td>
2772 </table>
2773 <!-- INDENTATION -->
2774 <table width="100%" border=0 rules="none" frame="void"
2775        cols="2" cellspacing="0" cellpadding="0">
2776 <tr valign="top" align="left">
2777 <td width="21%"></td>
2778 <td width="77%">
2779 <p><b>http://www.zsh.org/</b></p>
2780 </td>
2781 </table>
2782 <!-- INDENTATION -->
2783 <table width="100%" border=0 rules="none" frame="void"
2784        cols="2" cellspacing="0" cellpadding="0">
2785 <tr valign="top" align="left">
2786 <td width="10%"></td>
2787 <td width="89%">
2788 <p>The Z shell FAQ</p></td>
2789 </table>
2790 <!-- INDENTATION -->
2791 <table width="100%" border=0 rules="none" frame="void"
2792        cols="2" cellspacing="0" cellpadding="0">
2793 <tr valign="top" align="left">
2794 <td width="21%"></td>
2795 <td width="77%">
2796 <p><b>http://zsh.sunsite.dk/FAQ/</b></p>
2797 </td>
2798 </table>
2799 <!-- INDENTATION -->
2800 <table width="100%" border=0 rules="none" frame="void"
2801        cols="2" cellspacing="0" cellpadding="0">
2802 <tr valign="top" align="left">
2803 <td width="10%"></td>
2804 <td width="89%">
2805 <p>The Z shell wiki</p></td>
2806 </table>
2807 <!-- INDENTATION -->
2808 <table width="100%" border=0 rules="none" frame="void"
2809        cols="2" cellspacing="0" cellpadding="0">
2810 <tr valign="top" align="left">
2811 <td width="21%"></td>
2812 <td width="77%">
2813 <p><b>http://www.zshwiki.org/</b></p>
2814 </td>
2815 </table>
2816 <!-- INDENTATION -->
2817 <table width="100%" border=0 rules="none" frame="void"
2818        cols="2" cellspacing="0" cellpadding="0">
2819 <tr valign="top" align="left">
2820 <td width="10%"></td>
2821 <td width="89%">
2822 <p>Mailinglistarchive</p></td>
2823 </table>
2824 <!-- INDENTATION -->
2825 <table width="100%" border=0 rules="none" frame="void"
2826        cols="2" cellspacing="0" cellpadding="0">
2827 <tr valign="top" align="left">
2828 <td width="21%"></td>
2829 <td width="77%">
2830 <p><b>http://www.zsh.org/mla/</b></p>
2831 </td>
2832 </table>
2833 <!-- INDENTATION -->
2834 <table width="100%" border=0 rules="none" frame="void"
2835        cols="2" cellspacing="0" cellpadding="0">
2836 <tr valign="top" align="left">
2837 <td width="10%"></td>
2838 <td width="89%">
2839 <p>The Z shell reference-card (included in the
2840 zsh-lovers</p></td>
2841 </table>
2842 <!-- INDENTATION -->
2843 <table width="100%" border=0 rules="none" frame="void"
2844        cols="2" cellspacing="0" cellpadding="0">
2845 <tr valign="top" align="left">
2846 <td width="21%"></td>
2847 <td width="77%">
2848 <p>debian-package)
2849 <b>http://zsh.sunsite.dk/Refcard/refcard.ps.gz</b></p>
2850 </td>
2851 </table>
2852 <!-- INDENTATION -->
2853 <table width="100%" border=0 rules="none" frame="void"
2854        cols="2" cellspacing="0" cellpadding="0">
2855 <tr valign="top" align="left">
2856 <td width="10%"></td>
2857 <td width="89%">
2858 <p>Adam Spier&rsquo;s UNIX shells page</p></td>
2859 </table>
2860 <!-- INDENTATION -->
2861 <table width="100%" border=0 rules="none" frame="void"
2862        cols="2" cellspacing="0" cellpadding="0">
2863 <tr valign="top" align="left">
2864 <td width="21%"></td>
2865 <td width="77%">
2866 <p><b>http://adamspiers.org/computing/shells/</b></p>
2867 </td>
2868 </table>
2869 <!-- INDENTATION -->
2870 <table width="100%" border=0 rules="none" frame="void"
2871        cols="2" cellspacing="0" cellpadding="0">
2872 <tr valign="top" align="left">
2873 <td width="10%"></td>
2874 <td width="89%">
2875 <p>The Single UNIX (R) Specification, Version 2 - Shell
2876 Command Language Index</p></td>
2877 </table>
2878 <!-- INDENTATION -->
2879 <table width="100%" border=0 rules="none" frame="void"
2880        cols="2" cellspacing="0" cellpadding="0">
2881 <tr valign="top" align="left">
2882 <td width="21%"></td>
2883 <td width="77%">
2884
2885 <p><b>http://www.opengroup.org/onlinepubs/007908799/xcu/shellix.html</b></p>
2886 </td>
2887 </table>
2888 <!-- INDENTATION -->
2889 <table width="100%" border=0 rules="none" frame="void"
2890        cols="2" cellspacing="0" cellpadding="0">
2891 <tr valign="top" align="left">
2892 <td width="10%"></td>
2893 <td width="89%">
2894 <p>Zzappers Best of ZSH Tips</p></td>
2895 </table>
2896 <!-- INDENTATION -->
2897 <table width="100%" border=0 rules="none" frame="void"
2898        cols="2" cellspacing="0" cellpadding="0">
2899 <tr valign="top" align="left">
2900 <td width="21%"></td>
2901 <td width="77%">
2902 <p><b>http://www.rayninfo.co.uk/tips/zshtips.html</b></p>
2903 </td>
2904 </table>
2905 <!-- INDENTATION -->
2906 <table width="100%" border=0 rules="none" frame="void"
2907        cols="2" cellspacing="0" cellpadding="0">
2908 <tr valign="top" align="left">
2909 <td width="10%"></td>
2910 <td width="89%">
2911 <p>The ZSH area on dotfiles.com</p></td>
2912 </table>
2913 <!-- INDENTATION -->
2914 <table width="100%" border=0 rules="none" frame="void"
2915        cols="2" cellspacing="0" cellpadding="0">
2916 <tr valign="top" align="left">
2917 <td width="21%"></td>
2918 <td width="77%">
2919 <p><b>http://www.dotfiles.com/index.php3?app_id=4</b></p>
2920 </td>
2921 </table>
2922 <!-- INDENTATION -->
2923 <table width="100%" border=0 rules="none" frame="void"
2924        cols="2" cellspacing="0" cellpadding="0">
2925 <tr valign="top" align="left">
2926 <td width="10%"></td>
2927 <td width="89%">
2928 <p>Zsh Webpage by Christian Schneider</p></td>
2929 </table>
2930 <!-- INDENTATION -->
2931 <table width="100%" border=0 rules="none" frame="void"
2932        cols="2" cellspacing="0" cellpadding="0">
2933 <tr valign="top" align="left">
2934 <td width="21%"></td>
2935 <td width="77%">
2936 <p><b>http://strcat.neessen.net/zsh/</b></p>
2937 </td>
2938 </table>
2939 <!-- INDENTATION -->
2940 <table width="100%" border=0 rules="none" frame="void"
2941        cols="2" cellspacing="0" cellpadding="0">
2942 <tr valign="top" align="left">
2943 <td width="10%"></td>
2944 <td width="89%">
2945 <p>The zsh-lovers webpage</p></td>
2946 </table>
2947 <!-- INDENTATION -->
2948 <table width="100%" border=0 rules="none" frame="void"
2949        cols="2" cellspacing="0" cellpadding="0">
2950 <tr valign="top" align="left">
2951 <td width="21%"></td>
2952 <td width="77%">
2953 <p><b>http://grml.org/zsh/</b></p>
2954 </td>
2955 </table>
2956 <!-- INDENTATION -->
2957 <table width="100%" border=0 rules="none" frame="void"
2958        cols="2" cellspacing="0" cellpadding="0">
2959 <tr valign="top" align="left">
2960 <td width="10%"></td>
2961 <td width="89%">
2962 <p>IRC channel</p></td>
2963 </table>
2964 <!-- INDENTATION -->
2965 <table width="100%" border=0 rules="none" frame="void"
2966        cols="2" cellspacing="0" cellpadding="0">
2967 <tr valign="top" align="left">
2968 <td width="21%"></td>
2969 <td width="77%">
2970 <p><b>#zsh at irc.freenode.org</b></p>
2971 </td>
2972 </table>
2973 <a name="AUTHORS"></a>
2974 <h2>AUTHORS</h2>
2975 <!-- INDENTATION -->
2976 <table width="100%" border=0 rules="none" frame="void"
2977        cols="2" cellspacing="0" cellpadding="0">
2978 <tr valign="top" align="left">
2979 <td width="10%"></td>
2980 <td width="89%">
2981 <p>This manpage was written by Michael Prokop, Christian
2982 &acute;strcat&rsquo; Schneider and Matthias Kopfermann. But
2983 many ideas have been taken from zsh-geeks e.g. from the
2984 zsh-mailinglists (zsh-users and zsh-workers), google,
2985 newsgroups and the zsh-Wiki. Thanks for your cool and
2986 incredible tips. We learned much from you!</p>
2987 <!-- INDENTATION -->
2988 <p>In alphabetic order:</p>
2989 <!-- INDENTATION -->
2990 <pre>Andrew &rsquo;zefram&rsquo; Main  - http://www.fysh.org/~zefram/
2991 Barton E. Schaefer    - http://www.well.com/user/barts/
2992 Matthias Kopfermann   - http://www.infodrom.north.de/~matthi/
2993 Oliver Kiddle         - http://people.freenet.de/opk/
2994 Paul Falstad          - http://www.falstad.com/
2995 Peter Stephenson      - http://python.swan.ac.uk/~pypeters/
2996 Richard Coleman
2997 St&eacute;phane Chazelas     - http://stephane.chazelas.free.fr/
2998 Sven Guckes           - http://www.guckes.net/
2999 Sven Wischnowsky      - http://w9y.de/zsh/zshrc
3000 </pre>
3001 </td>
3002 </table>
3003 <a name="SEE ALSO"></a>
3004 <h2>SEE ALSO</h2>
3005 <!-- INDENTATION -->
3006
3007 <table width="100%" border=0 rules="none" frame="void"
3008        cols="2" cellspacing="0" cellpadding="0">
3009 <tr valign="top" align="left">
3010 <td width="10%"></td>
3011 <td width="89%">
3012 <p>Manpages of zsh:</p>
3013 <!-- INDENTATION -->
3014 <pre>zsh          Zsh overview (this section)
3015 zshmisc      Anything not fitting into the other sections
3016 zshexpn      Zsh command and parameter expansion
3017 zshparam     Zsh parameters
3018 zshoptions   Zsh options
3019 zshbuiltins  Zsh built-in functions
3020 zshzle       Zsh command line editing
3021 zshcompwid   Zsh completion widgets
3022 zshcompsys   Zsh completion system
3023 zshcompctl   Zsh completion control
3024 zshmodules   Zsh loadable modules
3025 zshzftpsys   Zsh built-in FTP client
3026 zshall       Meta-man page containing all of the above
3027
3028 Note: especially &rsquo;man zshcontrib&rsquo; covers very useful topics!
3029
3030 Book:
3031 From Bash to Z Shell
3032 by Oliver  Kiddle, Jerry Peck and Peter Stephenson
3033 ISBN: 1590593766
3034
3035 Also take a look at the section
3036 <b>LINKS
3037 </b>in this manpage.
3038
3039 </pre>
3040 </td>
3041 </table>
3042 <a name="BUGS"></a>
3043 <h2>BUGS</h2>
3044 <!-- INDENTATION -->
3045
3046 <table width="100%" border=0 rules="none" frame="void"
3047        cols="2" cellspacing="0" cellpadding="0">
3048 <tr valign="top" align="left">
3049 <td width="10%"></td>
3050 <td width="89%">
3051 <p>Probably. This manpage might be never complete. So please
3052 report bugs, feedback and suggestions to
3053 &lt;zsh-lovers@michael-prokop.at&gt;. Thank you!</p>
3054 </td>
3055 </table>
3056 <a name="COPYRIGHT"></a>
3057 <h2>COPYRIGHT</h2>
3058 <!-- INDENTATION -->
3059 <table width="100%" border=0 rules="none" frame="void"
3060        cols="2" cellspacing="0" cellpadding="0">
3061 <tr valign="top" align="left">
3062 <td width="10%"></td>
3063 <td width="89%">
3064 <p>Copyright &copy; 2005 Michael Prokop, Christian Schneider
3065 and Matthias Kopfermann.</p>
3066 </td>
3067 </table>
3068 <hr>
3069 </body>
3070 </html>