[X-Unix] Renaming files with spaces

Xavier Noria fxn at hashref.com
Sat May 23 14:38:37 PDT 2009


On Thu, May 14, 2009 at 4:26 PM, Charles Howse <chowse at charter.net> wrote:

> Hi,
> I need to batch rename all files with extension .PDF to extension .pdf.
> They may or may not have spaces in the filenames.
>
> The following works ONLY if there are no spaces in the filename:
>
> for f in *.PDF; do
>        base=`basename $f .PDF`
>        mv $f $base.pdf
> done
>
> Can anyone provide a tip to something that will work regardless of whether
> there are spaces in the filenames or not?

Put double quotes around each argument:

mv "$f" "$base.pdf"


More information about the X-Unix mailing list