Today I submit a case of an unexpected consequence of a shell command on some audio files that I do not understand at all.

Here are the facts:

  1. My OS is ArchLinux, the windows manager is Awesome and the terminal used is Konsole.

  2. Having many directories and files containing spaces and/or specific characters as ',{,[,?,! I wanted to rename them by removing any spaces and/or specific characters.

  3. Looking for a shell command, I found this one to replace (for example) the _ character by a .:

$ find ./ -type f -exec sed -i -e 's/_/./g' {} \;

  1. I used this command on many directories in which all the files have been renamed as expected, I was happy with it.


  1. Having some directories containing some audio files that I wanted to rename, I applied this bash command on these directories. Contrary to the previous uses, the process a longer time and at its end the result was not was I expected. First most of the files have not been renamed. Second all the audio files (mp3, flac, ...) have been altered/corrupted and are no longer identified by any audio file reader. By contrast the audio files on which I did not use the bash command are always right and can be read.

For example when I try to read one of the altered file with smplayer, the error message is: MPlayer/mpv has finished unexpectedly. Exit code: 2. The log file adds: 'Failed to recognize file format.'

Referring to the first answer, I give below additional information about the effects of the alteration.

Having used 3 commands to get what I wanted:

  • find ./ -type f -exec sed -i -e 's/_/./g' {} \;

  • find ./ -type f -exec sed -i -e 's/ /./g' {} \;

  • find ./ -type f -exec sed -i -e 's/.././g' {} \;

Here some examples of files names before > after corruption:

1_-_Bob_The_Sponge_-_Living under the Sea.flac > 1.-.Bob.The.Sponge.-. Living.under the Sea.flac (note some spaces are still present)

2_-_Bob_The_Sponge_-_Nemo_my_friend.mp3 > 2.-.Bob_The.Sponge.-.Nemo my.friend.mp3 (note one '_' has not been removed and one space has been added in the name).

All the cases can not be reproduced here, some file names have been well changed, some other partially, some other are as before.

The weight of the altered files have not changed, nor the rights of these files. Only the date of the last modification has changed.

Naturally, I would like to understand what has happened. I tried to find explanations with different browsers but I did not find any similar or close problems.

So, my questions are:

  1. Why this bash command seems to have altered these audio files?
  2. Why this command has effect on this type of file and not on the other ones?
  3. What could be the solution to reverse the damages of this command on these files?
  • 2
    Could you add some examples of filenames where the contents have been altered? In what way have the contents been altered? For example, is the size the same? mv by itself cannot alter contents, so my first idea is that's some side effect of some other commands that accidentally got executed.
    – dirkt
    Nov 12, 2016 at 11:45
  • Can you reproduce that problem? With one file only?
    – pfnuesel
    Nov 12, 2016 at 13:15
  • Thank you guys for your answers that gave me the idea to look into the bash_history to find the command used. It is not the one I gave you first. Sorry about that, I really thought that it was this one. But it was not. I modify my text with the command used.
    – corto037
    Nov 12, 2016 at 14:02
  • @pfnuesel: Yes, using the command mentioned in the text, I can reproduce the alteration of some audio files.
    – corto037
    Nov 12, 2016 at 14:04
  • 1
    With sed you change the content of the file...
    – pfnuesel
    Nov 12, 2016 at 14:14

1 Answer 1


You used the following command

find ./ -type f -exec sed -i -e 's/_/./g' {} \;

What this basically does is

sed -i -e 's/_/./g' filename

for each file found by the find command. sed goes through your files, line by line, and the s (substitute) command, replaces each _ with a .. And since you are using the -i flag, this happens inline. No wonder your files got corrupted!

You will not be able to reproduce your old files. You changed _, and .. to .. All you know is that each . in your files, could be one of these characters (or a .).

  • Thank you very much for this clear reply. This case learnt me to be more cautious about command line. I just wanted to get a short cut (renaming many subdirectories with only one command) and all my files are now altered. A simple 'mv' command would have need more time (one for each directory) but with a safe result. Thanks again!
    – corto037
    Nov 12, 2016 at 14:28
  • 1
    @corto037 Good! If this solves your issue, please consider accepting the answer.
    – Kusalananda
    Feb 3, 2017 at 9:01

You must log in to answer this question.

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