And if you want the number of errors allowed by _approximate to
increase with the length of what you have typed so far:
---------------------------------------------------------------------------------------------------
And if you want the number of errors allowed by _approximate to
increase with the length of what you have typed so far:
---------------------------------------------------------------------------------------------------
max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
---------------------------------------------------------------------------------------------------
max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)'
---------------------------------------------------------------------------------------------------
# Fetch the newest file containing the string 'fgractg*.log' in the
# filename and contains the string 'ORA-' in it
# Fetch the newest file containing the string 'fgractg*.log' in the
# filename and contains the string 'ORA-' in it
$ (($#file)) && grep -l ORA- $file
# without Zsh
$ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
$ (($#file)) && grep -l ORA- $file
# without Zsh
$ files=$( find . -name . -o -prune -name 'fgractg*>log' -mtime 0 -print )
> fi
# keep specified number of child processes running until entire task finished
$ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
> fi
# keep specified number of child processes running until entire task finished
$ zsh -c 'sleep 1 & sleep 3 & sleep 2& print -rl -- $jobtexts'
# Remove zero length and .bak files in a directory
$ rm -i *(.L0) *.bak(.)
# print out files that dont have extensions
$ printf '%s\n' ^?*.*
$ printf '%s\n' ^?*.[^.]*(D)
# Remove zero length and .bak files in a directory
$ rm -i *(.L0) *.bak(.)
# print out files that dont have extensions
$ printf '%s\n' ^?*.*
$ printf '%s\n' ^?*.[^.]*(D)
# Finding files which does not contain a specific string
$ print -rl file* | comm -2 -3 - <(grep -l string file*)'
$ for f (file*(N)) grep -q string $f || print -r $f'
# Finding files which does not contain a specific string
$ print -rl file* | comm -2 -3 - <(grep -l string file*)'
$ for f (file*(N)) grep -q string $f || print -r $f'
# Count the number of directories on the stack
$ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
$ dirs -v | awk '{n=$1}END{print n+1}'
# Matching all files which do not have a dot in filename
$ ls *~*.*(.)
# Count the number of directories on the stack
$ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) # or
$ dirs -v | awk '{n=$1}END{print n+1}'
# Matching all files which do not have a dot in filename
$ ls *~*.*(.)
# load all available modules at startup
$ typeset -U m
$ m=()
$ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
$ zmodload -i $m
# load all available modules at startup
$ typeset -U m
$ m=()
$ for md ($module_path) m=($m $md/**/*(*e:'REPLY=${REPLY#$md/}'::r))
$ zmodload -i $m
# prefix in the default sort order.
$ i=1; for j in *; do mv $j $i.$j; ((i++)); done
$ i=1; for f in *; do mv $f $(echo $i | \
awk '{ printf("%03d", $0)}').$f; ((i++)); done
$ integer i=0; for f in *; do mv $f $[i+=1].$f; done
# prefix in the default sort order.
$ i=1; for j in *; do mv $j $i.$j; ((i++)); done
$ i=1; for f in *; do mv $f $(echo $i | \
awk '{ printf("%03d", $0)}').$f; ((i++)); done
$ integer i=0; for f in *; do mv $f $[i+=1].$f; done
-# Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
+# Get the PID of a process (without ``ps'', ``sed'', ``pgrep'', ..
sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
# If `foo=23'', then print with 10 digit with leading '0'.
$ foo=23
$ print ${(r:10::0:)foo}
sh -c ' exec mkdir -p -- "$d/$1"' '{}' '{}' \;
# If `foo=23'', then print with 10 digit with leading '0'.
$ foo=23
$ print ${(r:10::0:)foo}
$ eval "m=($(cat -- $nameoffile)" # or use
$ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
$ eval "m=($(cat -- $nameoffile)" # or use
$ m=("${(@Q)${(z)"$(cat -- $nameoffile)"}}") # to restore it
-# get a "ls -l" on all the files in the tree that are younger than a
-# specified age (e.g "ls -l" all the files in the tree that where
+# get a "ls -l" on all the files in the tree that are younger than a
+# specified age (e.g "ls -l" all the files in the tree that where
# Download with LaTeX2HTML created Files (for example the ZSH-Guide):
$ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
> lynx -source $f >${f:t}
> done
# Download with LaTeX2HTML created Files (for example the ZSH-Guide):
$ for f in http://zsh.sunsite.dk/Guide/zshguide{,{01..08}}.html; do
> lynx -source $f >${f:t}
> done
-# A small one-liner, that reads from stdin and prints to stdout the first
-# unique line i. e. does not print lines that have been printed before
-# (this is similar to the unique command, but unique can only handle
+# A small one-liner, that reads from stdin and prints to stdout the first
+# unique line i. e. does not print lines that have been printed before
+# (this is similar to the unique command, but unique can only handle
(Recursive) Globbing - Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A list of valid glob Qualifiers can be found in zshexpn(1). *Note:*
(Recursive) Globbing - Examples
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A list of valid glob Qualifiers can be found in zshexpn(1). *Note:*
# general, directories that contain more than one file matching "index.*"
$ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
# or
# general, directories that contain more than one file matching "index.*"
$ ls **/*(D/e:'[[ -e $REPLY/index.php && -e $REPLY/index.html ]]':)
# or
$ find / | grep -e /path/ -e '/path$'
# Print he path of the directories holding the ten biggest C regular files
$ find / | grep -e /path/ -e '/path$'
# Print he path of the directories holding the ten biggest C regular files
-# in the current directory and subdirectories.
- $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
+# in the current directory and subdirectories.
+ $ print -rl -- **/*.c(D.OL[1,10]:h) | sort -u
-# Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
-# (recursive, include dotfiles) remove the setgid/setuid flag and print
+# Search all files in /home/*/*-mail/ with a setting ``chmod -s'' flag
+# (recursive, include dotfiles) remove the setgid/setuid flag and print
# long error
$ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
# List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
$ ls -l foo<23->
# long error
$ zargs /home/*/*-mail(DNs,S) /home/*/*-mail/**/*(DNs,S)) -- chmod -s
# List files beginning at `foo23' upwards (foo23, foo24, foo25, ..)
$ ls -l foo<23->
example:
$ zmodload zsh/files ; rm -f **/*(mh+6)
or use the zargs function:
$ autoload zargs ; zargs **/*(mh+6) -- rm -f
example:
$ zmodload zsh/files ; rm -f **/*(mh+6)
or use the zargs function:
$ autoload zargs ; zargs **/*(mh+6) -- rm -f
-# A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
-# Matching find all files in all subdirectories, searching recursively,
-# which have a given name, case insensitive, are at least 50 KB large,
-# no more than a week old and owned by the root user, and allowing up
-# to a single error in the spelling of the name. In fact, the required
+# A User's Guide to the Z-Shell /5.9: Filename Generation and Pattern
+# Matching find all files in all subdirectories, searching recursively,
+# which have a given name, case insensitive, are at least 50 KB large,
+# no more than a week old and owned by the root user, and allowing up
+# to a single error in the spelling of the name. In fact, the required
# display the 5-10 last modified files
$ print -rl -- /path/to/dir/**/*(D.om[5,10])
# display the 5-10 last modified files
$ print -rl -- /path/to/dir/**/*(D.om[5,10])
# find all files without a valid owner
$ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
# find all the empty directories in a tree
$ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
# Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
# find all files without a valid owner
$ chmod someuser /**/*(D^u:${(j.:u:.)${(f)"$(</etc/passwd)"}%%:*}:)
# find all the empty directories in a tree
$ for f in ***/*(/l2); do foo=($f/*(N)); [[ -z $foo ]] && print $f; done
# Note:Since Zsh 4.2.1 the glob qualifier F indicates a non-empty directory.
returned by parameter, filename and history expansion. See zshexpn(1)
for details.
-------------------------------------------------------------------------------
returned by parameter, filename and history expansion. See zshexpn(1)
for details.
-------------------------------------------------------------------------------
$ for f (*.sh) mv $f $f:r
# Remove a filename extension of the form `.xxx', leaving the root name.
$ for f (*.sh) mv $f $f:r
# Remove a filename extension of the form `.xxx', leaving the root name.
# pipe single output to multiple inputs
$ zcat foobar.Z >> (gzip -9 > file1.gz) \
>> (bzip2 -9 > file1.bz2) \
# pipe single output to multiple inputs
$ zcat foobar.Z >> (gzip -9 > file1.gz) \
>> (bzip2 -9 > file1.bz2) \
$ command 2>&2 2>stderr
# redirect stderr and stdout to separate files and both to orig. stdout:
$ command 2>&1 1>&1 2>stderr 1>stdout
$ command 2>&2 2>stderr
# redirect stderr and stdout to separate files and both to orig. stdout:
$ command 2>&1 1>&1 2>stderr 1>stdout
# Remove the first 4 chars from a filename
$ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
# Remove the first 4 chars from a filename
$ zmv -n '*' '$f[5,-1]' # NOTE: The "5" is NOT a mistake in writing!
-# Rename names of all files under the current Dir to lower case, but keep
-# dirnames as-is.
- $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
+# Rename names of all files under the current Dir to lower case, but keep
+# dirnames as-is.
+ $ zmv -Qv '(**/)(*)(.D)' '$1${(L)2}'
$ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
# lowercase all extensions (i. e. *.JPG) incl. subfolders
$ zmv -n '(**/)(con*)(#qe,file $REPLY | grep "python script",)' '$1$2.py'
# lowercase all extensions (i. e. *.JPG) incl. subfolders
$ ls
filename.001 filename.003 filename.005 filename.007 filename.009
filename.002 filename.004 filename.006 filename.008 filename.010
$ ls
filename.001 filename.003 filename.005 filename.007 filename.009
filename.002 filename.004 filename.006 filename.008 filename.010
$ ls *
foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
$ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
$ ls *
foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
$ ls *
foo_10.jpg foo_2.jpg foo_3.jpg foo_4.jpg foo_5.jpg foo_6.jpg ..
$ zmv -fQ 'foo_(<0->).jpg(.nOn)' 'foo_$(($1 + 1)).jpg'
$ ls *
foo_10.jpg foo_11.jpg foo_3.jpg foo_4.jpg foo_5.jpg ...
$ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
# See above, but now only files with a filename >= 30 chars
$ zmv '(<1->).jpg' '${(l:3::0:)1}.jpg'
# See above, but now only files with a filename >= 30 chars
$ zmv -W '*.sh' '*.pl'
# Add a "".txt" extension to all the files within ${HOME}
# ``-.'' is to only rename regular files or symlinks to regular files,
# ``D'' is to also rename hidden files (dotfiles))
$ zmv -W '*.sh' '*.pl'
# Add a "".txt" extension to all the files within ${HOME}
# ``-.'' is to only rename regular files or symlinks to regular files,
# ``D'' is to also rename hidden files (dotfiles))
$ zmv -Q '/home/**/*(D-.)' '$f.txt'
# Or to only rename files that don't have an extension:
$ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
# Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
$ zmv -Q '/home/**/*(D-.)' '$f.txt'
# Or to only rename files that don't have an extension:
$ zmv -Q '/home/**/^?*.*(D-.)' '$f.txt'
# Recursively change filenames with characters ? [ ] / = + < > ; : " , - *
-# When a new file arrives (named file.txt) rename all files in order to
-# get (e. g. file119.txt becomes file120.txt, file118.txt becomes
+# When a new file arrives (named file.txt) rename all files in order to
+# get (e. g. file119.txt becomes file120.txt, file118.txt becomes
$ zmv '(*)' '${(L)1}' # lowercase
$ zmv '(*)' '${(U)1}' # uppercase
# Remove the suffix *.c from all C-Files
$ zmv '(*)' '${(L)1}' # lowercase
$ zmv '(*)' '${(U)1}' # uppercase
# Remove the suffix *.c from all C-Files
$ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
# Copy the target `README' in same directory as each `Makefile'
$ zmv '([a-z])(*).mp3' '${(C)1}$2.mp3'
# Copy the target `README' in same directory as each `Makefile'
$ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
# Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
$ zmv -Q "(**/)(*'*)(D)" "\$1\${2//'/}"
# Rename pic1.jpg, pic2.jpg, .. to pic0001.jpg, pic0002.jpg, ..
$ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
$ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively
-------------------------------------------------------------------------------
$ zmv 'pic(*).jpg' 'pic${(l:4::0:)1}.jpg'
$ zmv '(**/)pic(*).jpg' '$1/pic${(l:4::0:)2}.jpg' # recursively
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
# Copy files of a certain period (date indicated in the filenames)
-------------------------------------------------------------------------------
# Copy files of a certain period (date indicated in the filenames)
zsh/clone (require zmodload zsh/clone)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
zsh/clone (require zmodload zsh/clone)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
# execute ``command'' on /dev/tty8 (for this example).
$ zmodload zsh/clone
$ clone /dev/tty8 && (($! == 0)) && exec command
# execute ``command'' on /dev/tty8 (for this example).
$ zmodload zsh/clone
$ clone /dev/tty8 && (($! == 0)) && exec command
- $ zmodload -i zsh/datetime
- $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
- $ files=(**/$file(N.L0))
- $ (( $#files > 0 )) && print -rl -- $files | \
- mailx -s "empty files" foo@bar.tdl
+ $ zmodload -i zsh/datetime
+ $ strftime -s file "abc_de_%m%d%Y.dat" $((EPOCHSECONDS - 24 * 60 * 60 ))
+ $ files=(**/$file(N.L0))
+ $ (( $#files > 0 )) && print -rl -- $files | \
+ mailx -s "empty files" foo@bar.tdl
-------------------------------------------------------------------------------
zsh/stat (require zmodload zsh/stat)
-------------------------------------------------------------------------------
zsh/stat (require zmodload zsh/stat)
# deletion.
$ zmodload zsh/stat zsh/files
$ typeset -A f; f=()
$ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
$ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
# deletion.
$ zmodload zsh/stat zsh/files
$ typeset -A f; f=()
$ rm -f /path/**/*(.a+10e{'stat -sA u +uidr $REPLY; f[$u]="$f[$u]$REPLY"'})
$ for user (${(k)f}) {print -rn $f[$user]|mailx -s "..." $user}
-------------------------------------------------------------------------------
zsh/files (require zmodload zsh/files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
zsh/files (require zmodload zsh/files)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
-
-# If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
-# this empty tags (ones ending in '/>') so if encountered in the same
-# order, the preceeding tags would become ``<TAGA/>1</TAGA>'' and
+
+# If a XML-file contains stuff like ``<TAGA/>'' and ``<TAGB/>'', number
+# this empty tags (ones ending in '/>') so if encountered in the same
+# order, the preceeding tags would become ``<TAGA/>1</TAGA>'' and
# removing all files in users Maildir/new that contain ``filename="gone.src''
$ zmodload zsh/{files,mapfile}
# removing all files in users Maildir/new that contain ``filename="gone.src''
$ zmodload zsh/{files,mapfile}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
$ autoload -U zfinit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------------------------------
$ autoload -U zfinit
# two hours to ftp.foobar.invalid/path/to/upload
$ autoload -U zfinit ; zfinit
$ zfopen ftp.foobar.invalid/path/to/upload
$ cd $HOME/foobar
$ zfput -r **/*(.mh-2)
$ zfclose
# two hours to ftp.foobar.invalid/path/to/upload
$ autoload -U zfinit ; zfinit
$ zfopen ftp.foobar.invalid/path/to/upload
$ cd $HOME/foobar
$ zfput -r **/*(.mh-2)
$ zfclose
$EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath
------------------------------------------------------
$EUID $GID $EGID $USERNAME $fignore $mailpath $cdpath
------------------------------------------------------
zshall Tthe Z shell meta-man page
zshbuiltins Zsh built-in commands
zshcompctl Zsh completion control
zshall Tthe Z shell meta-man page
zshbuiltins Zsh built-in commands
zshcompctl Zsh completion control