I'm trying to rename a bunch of music tracks in a directory, but I got this error:When moving multiple files, last argument must be a directoryThis is the script: for file in * ; do    mv $file  $(echo $file |sed 's/^.\{5\}//g')doneThis works for a file without whitespace, how would I modify this script?
Remove certain characters from multiple files with whitepsaces
linux;bash;scripting;sed
Use quotes:mv -- $file $(echo $file | sed ...)Else mv sees multiple arguments. A filename called file name with spaces would be 4 arguments for mv. Therefore the error: when moving multiple files, last argument must be a directory. When mv has more than 2 arguments, it's assuming you want to move multiple files to a directory (which would then be the last argument).But however, it looks like you want to remove the first 5 characters from the filename. That can be done simpler with bash:mv -- $file ${file:5}Edit: I added the -- flag, thanks to the comment of @pabouk. Now file starting with dash - are also correctly processed.