converting %20 to a space in directory names

Steve Coile scoile at nandomedia.com
Sat Aug 9 05:10:37 PDT 2003


On Sat, 9 Aug 2003, Vincent Zee wrote:
>I have 5000 directory names with %20 in its names and would like to
>replace them with 1 space.
>I only want to change the directory names and leave its contents
>untouched. Also I need to do this recursively (directories in
>directories).
>I checked google but the answers I found were for files in directories.

Completely untested.  Use at your own risk.

Replace "TOPDIR" with the name of the top of the directory tree.

	find TOPDIR -depth -type d -name '*%20*' -print \
	| while read old
	do
		new="`echo \"${old}\" | sed -e 's/%20/ /g'`"
		( set -x; mv "${old}" "${new}" )
	done

-- 
Steve Coile


More information about the freebsd-questions mailing list