File name problem(?)

filenamesmv

I have downloaded audio with youtube-dl, and then I wanted to change name with mv:

mv "Powerwolf  - Resurrection By Erection-Hiu1hPdJk-Y.mp3" "Powerwolf - Resurrection by Errection.mp3
>"

But, when I want to do something with renamed file, bash prints:

root@bananapi:~/Music# mv "Powerwolf - Resurrection by Errection.mp3 " All
mv: cannot stat 'Powerwolf - Resurrection by Errection.mp3 ': No such file or directory

When I type ls -l, bash prints:

root@bananapi:/home/music/Music# root@bananapi:/home/music/Music# ls -l
total 3860
drwxr-xr-x 2 music music    4096 Apr 19 11:49 All
-rw-r--r-- 1 music music     360 Apr 19 12:34 download.py
drwxr-xr-x 2 music music    4096 Apr 19 11:48 Eleven
drwxr-xr-x 2 music music    4096 Apr 18 20:49 KlemenSlakonja
drwxr-xr-x 2 music music    4096 Apr 19 11:49 LittleBig
drwxr-xr-x 2 music music    4096 Apr 18 20:28 Powerwolf
-rw-r--r-- 1 root  root  3924591 Oct 24 15:03 Powerwolf - Resurrection by Errection.mp3 ?

Now, I want to delete this file, but I can't.

Best Answer

Your initial mv renamed the file to a name containing a newline at the end. You forgot to close the quoted string of the new name and pressed Enter. After pressing Enter (inserting a newline), you closed the double quote. This inserted a newline into the filename.

To rename the file, use

mv $'Powerwolf - Resurrection by Errection.mp3 \n' 'Powerwolf - Resurrection by Errection.mp3'

Note the space before the \n. It looks like this should be there according to the ls output.

You could also use a * to match the end of the name with a newline:

mv "Powerwolf - Resurrection by Errection.mp3"* "Powerwolf - Resurrection by Errection.mp3"
Related Question