Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: removing spaces from a file name



zzapper wrote:
> Hi
> I still dislike spaces in file names:-
> 
> mv Licence\ to\ Print\ Money.pdf !#^:gs/ //
> 
> Is there a better/other way?

I use zmv for this; it's distributed with the shell and documented in
zshcontrib, so see that for more information.

  autoload -U zmv
  zmv '(* *)' '${1// /_}'

This acts on all files in the current directory with at least one space
in the name (the first pattern---note the quotes).  The parenthesis can
be referred to in the second argument as $1.  The substitution does
basically what you did with the history, except that I replace the space
with a "_".  Obviously, you can turn this into a function.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author