1

I have a number of files with double quotes in the filename like this:

"This_is_a_long_filename_with_quotes".mp3

I try to use the linux command rename, I can erase the underscore easily using

rename 's/_//g' *

but when I try with \" nothing happens (I use -n to see the changes):

rename -n 's/\"//g' *

nothing is renamed

thanks!

3
  • You say ls | grep \" returns nothing. How about echo *\"* or ls *\"*? If none of these commands show anything, you don't have files with double quotes in their names; you have files with pairs of single quotes in their names. Try ls | grep \', echo *\'* or ls *\'*. If those commands find your files, rename them with rename -n "s/'//g" *. Sep 4, 2014 at 22:09
  • Right they are not double quotes! see the comment below
    – Leosar
    Sep 4, 2014 at 22:45
  • They are "curly quotes". Try two rename operations while cutting and pasting the exact quote characters (open and close).
    – beroe
    Sep 4, 2014 at 23:39

3 Answers 3

4

You have "smart quotes" in your file names:

“Tokyo_String_Quartet-Beethoven_-Late_String_Quartets-CD1-11-Quartet”.mp3 

Try the rename command with those inserted instead of "

Or without using rename you can do the sed option:

for f in *.mp3
    do
        new=$(echo $f | sed -E 's/[“”]//g')
        mv $f $new
    done

As with all batch shell operations using mv it is safest to test/run on a backup of the original folder... You can test by putting echo in place of mv when you first try it.

1

There is no need to escape escape double quote inside single guote.

rename -n 's/"//g' *
3
  • Anyway nothing is renamed with or without escape I don't know why
    – Leosar
    Sep 4, 2014 at 21:53
  • 1) On my debian rename is a soft link to another softlink in /etc/alternatives. Chase the links and use dpkg -S ... on the final file to find package providing the executable. 2) Use dpkg -l package_name to find package version --> on my system with rename-0.20-3 the above command reported rewrites you wanted. 3) Which shell do you use? echo $SHELL
    – AnFi
    Sep 4, 2014 at 22:06
  • The problem is that they are not double quotes as suggested by @WildVelociraptor
    – Leosar
    Sep 4, 2014 at 22:43
0

I was able to do it in Bash with this:

file=$(ls | grep \")
newName=$(echo $file | sed 's/\"//g')
mv $file $newName
5
  • Maybe the same problem here, because ls | grep \" returns nothing
    – Leosar
    Sep 4, 2014 at 22:01
  • Are you sure they're double quotes? It may help to copy and paste the filename elsewhere, to see how it's rendered. It might also be an issue with way the filename is encoded; ASCII vs Unicode, maybe?
    – zymhan
    Sep 4, 2014 at 22:19
  • Ohh they are not, this is the file name: “Tokyo_String_Quartet-Beethoven_-Late_String_Quartets-CD1-11-Quartet,_Op._131_in_C_sharp_minor-_Allegro”.mp3
    – Leosar
    Sep 4, 2014 at 22:40
  • 1
    You need to cut and paste the opening and closing double quotes and use 's/[“”]//g' in your rename. (PS I don't have this trouble with my Lindsay Quartet recordings!)
    – AFH
    Sep 4, 2014 at 23:42
  • I have just seen that @beroe has made the same point under the original question, but I'll let my comment stand, as I have given the edit command you require.
    – AFH
    Sep 4, 2014 at 23:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .