Zsh tips & tricks

.: zmv examples ['autoload zmv' required] :.

:: recursivelly rename files/dirs — replace arbitrary number of spaces into one dash ..
% zmv '(**/)(* *)' '$1${2//( #-## #| ##)/_}'
:: recursivelly rename files — lowercase extensions (in this case *.JPG) ..
% zmv '(**/)(*).(#i)jpg' '$1$2.jpg'
:: replace spaces in filenames with an underline ..
% zmv '* *' '$f:gs/ /_'
:: recursively change filenames with characters ? [ ] / = + < > ; : " , - *
% chars='[][?=+<>;",*-]'
% zmv '(**/)(*)' '$1${2//$~chars/%}'
:: lowercase/uppercase all files/directories ..
% zmv '(*)' '${(L)1}' # lowercase
% zmv '(*)' '${(U)1}' # uppercase
:: remove the suffix '*.sh' from all shell-files ..
% zmv '(*).sh' '$1'

.: zftp examples ['autoload -U zfinit' required] :.

:: automatically transfer files using FTP with error checking ..
% autoload -U zfinit ; zfinit
% zftp open host.name.invalid user passwd || exit
% zftp get /remote/file > /local/file; r=$?
% zftp close && exit r
:: compress and ftp on the fly ..
% autoload -U zfinit ; zfinit
% zftp open host.name.invalid user password
% zftp get $file | bzip2 > ${file}.bz2
% zftp close
:: recursive 'get' ..
% autoload -U zfinit ; zfinit
% zfanon cr.yp.to
% zfcd daemontools
% for file in `zfls`; do zfget $file; done
% zfclose