0

I recently ripped my 600+ album collection to FLAC, and up until now i never noticed there was something wrong with the files. See the files themselves look normal viewing them from within Mint. And they all play fine.

Picture of files from the filebrowser

Everything looks fine here right. But i noticed when trying to actually share these files with my Windows machine that they would not play, nor would they copy. Windows gave me an error saying the filenames where too long. And i knew that was BS because they are clearly not. So this sent me down a spiral thinking the issue was samba.

Turns out when i browse the album folders each of the FLAC files have a ? before the end of them.

File names from the console

If i go into properties this ugly thing is hidden in there instead of the ? from the console.

Symbol in properties

And this is where my frustration really started. I found a console command that actually does solve part of my problem.

enter image description here

When entered in the album folder it strips away the ? mark, but leaves a space between the song name and the file extension.

enter image description here

So way too long story short, is there a better way of removing the ? from all my FLAC files in one swoop while also not making a space where the symbol would be?

Or do i really have to manually go through each album do the command and then manually do a backspace on each file. I really hope some of you are way better at these things then i am.

UPDATE

First of all thank you to all the people who gave advice on how to fix this.

I solved my problem by running this:

find -name $'*\n*' -exec rename $'s|\n||g' '{}' \;

It found every file in my music folder with the newline symbol and also manages to insert nothing so that the file name now ends in blank.flac instead of a blank(space).flac.

  • 2
    Those aren't actual question marks. That's ls saying "I don't know how to print this character". I'd use basename, strip the last character, and tack the extension back on it. – DopeGhoti May 24 '18 at 16:48
  • It's a linefeed/newline character (\012 or /n). You can see that from the GUI "strange symbol". Repeat your tr attempt but with that instead of a literal question mark. – roaima May 24 '18 at 22:44
3

To strip any character likely to be unloved by Windows from the filenames of FLAC files in the current directory:

for f in *.flac; do
  mv "$f" "$(echo -n "$f" | tr -cd ' -~' | tr '<>:"/\\|?*' '_')"
done

This will:

  • Delete any non-ASCII or non-printable characters in the filename: tr -cd ' -~';

  • Replace with underscores any printable ASCII characters which Windows doesn't accept: tr '<>:"/\\|?*' '_'.

In particular, your filenames have a '\n' (newline, U+000A) just before .flac.

  • This is exactly what i needed. Is there any way i can do this on the top folder so that the command goes through sub folders? – Daniel Nielsen May 24 '18 at 18:04
  • That's a different question. There are many ways to iterate through all the folders in a subtree. – AlexP May 24 '18 at 18:53
  • 1
    If you're using bash, just add shopt -s globstar nullglob before the for loop and change *.flac to **/*.flac. – m0dular May 24 '18 at 20:09
  • Also, nice taste in music ;) – m0dular May 24 '18 at 20:12
  • Haha thanks. Also thank you for the string will go test it out right away. – Daniel Nielsen May 24 '18 at 22:04
2

The answer by AlexP is a great one, but if you're willing to install some extra software, there's an even easier option.

Look into detox. It's a dead-simple program packaged by most distributions that does almost exactly the same thing as the shell script AlexP posted, while automatically iterating through the entire folder it's run on. For the sheer simplicity of use, it's on the reasonably short list of programs I install on pretty much every Linux system I set up.

As yet another alternative for files in a single directory, renameutils will let you quickly and easily do batch renames from the terminal using your preferred text editor. When used with a Vi or EMACS style editor, it provides a reasonably easy way to perform complex batch transformations on filenames using the editor's built-in regular expression support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.