[X-Unix] Renaming files with spaces

Juan Manuel Palacios jmpalaciosp at eml.cc
Mon May 25 09:20:32 PDT 2009


On May 14, 2009, at 9:56 AM, Charles Howse 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?


	I would try double-quoting both the $f and the $base.pdf args in the  
mv command, i.e.:

mv "$f" "$base.pdf"

	In any case, you can always do a "set -x" just before the loop to see  
what each line in every iteration is producing.

	Let me know if it works, hope it helps!


-jmpp



More information about the X-Unix mailing list