[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: В текущем каталоге и его подкаталогах, все файлы в именах которых содержется пробел заменить их на знак "_".



> Доброго времени суток, многоуважемые.
> 
> Вот для решения сабжа попробовал использовать find,
> find ./ -type f -regex ".* .*" -exec mv {} `echo {}|tr ' ' '_'` \;
> но не добился желаемого:
> 
> stalker@ux /tmp/testdir $ ls -1
> 1 test file.txt
> 2 test file.txt
> 3 test file.txt
> stalker@ux /tmp/testdir $ find ./ -type f -regex ".* .*" -exec mv {} `echo {}|tr ' ' '_'` \;
> mv: `./2 test file.txt' and `./2 test file.txt' are the same file
> mv: `./3 test file.txt' and `./3 test file.txt' are the same file
> mv: `./1 test file.txt' and `./1 test file.txt' are the same file
> 
> Подскажите пожалуйста где ошибся?

for i in *; do
	name_out=`echo $i|sed "s/ /_/g"`
	if [ "$i" = "$name_out" ]; then
		echo $i не переименовываем
	else
		echo $i переименовываем в $name_out
		mv $i $name_out
	fi
done



Reply to: