3

My music library contains many .flac files that need the "?" removed from the filename as my current music player (Sonos) cannot for some reason see those files.

Is there a command or script that would help me find & remove question marks "?" in my music directory?

Directory setup:

~/music/artist/album/01 title with?.flac

Thank you

2
  • 1
    This isn't the best answer, since it's possible to write a script to do this, but if you have a bit of extra cash, check out A Better Finder Rename: publicspace.net/ABetterFinderRename
    – Eric
    Commented Jan 4, 2014 at 5:26
  • Thank you Eric that seems like a pretty good program I will bookmark it.
    – spacecat
    Commented Jan 4, 2014 at 21:13

1 Answer 1

4

Open Terminal and change to your directory, then use the command listed to remove all occurrences of ? within your filenames in that directory:

cd ~/music/artist/album/

for f in *; do mv -- "$f" "${f//\?/}"; done

Before you commit to runing the command you can test it, which will show you the original filename followed by new one:

for f in *; do echo -- "$f" "${f//\?/}"; done

-- 01 title with?.flac 01 title with.flac

To do this recursively you'll need to use the find command, and definitely try it in a test directory first. Messing up on the replacement strings of all your filenames could make things far worse than better. For recursive operations such as this I always recommend backing up your data beforehand.

The first command is the dry run, meaning nothing is actually changed. The second command is the real thing, which recursively renames all filenames (eliminating question marks) in the current directory and all sub-directories:

find . -type f -name '*\?*' | while read f; do echo mv "$f" "${f//\?/}"; done

find . -type f -name '*\?*' | while read f; do mv "$f" "${f//\?/}"; done
4
  • l'L'l, can this be applied to all the directories within ~/music? As it stands now, I will have to navigate to each album's directory and run this command. Thanks for your help.
    – spacecat
    Commented Jan 4, 2014 at 21:19
  • That is VERY cool! That's in the bash shell, I assume?
    – Eric
    Commented Jan 5, 2014 at 2:34
  • @spacecat, I've updated the answer to reflect with an additional command to recursively rename your files.
    – l'L'l
    Commented Jan 5, 2014 at 6:03
  • @Eric, — indeed it is (+ bash shell) :)
    – l'L'l
    Commented Jan 5, 2014 at 6:13

You must log in to answer this question.

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