Linux – Batch renaming of files in a directory using sed

bashlinuxsedUbuntu

I run a script which generated about 10k files in a directory. I just discovered that there is a bug in the script which causes some filenames to have a carriage return (presumably a '\n' character).

I want to run a sed command to remove the carriage return from the filenames.

Anyone knows which params to pass to sed to clean up the filenames in the manner described?

I am running on Linux (Ubuntu)

UPDATE

The character causing the filename to 'break up' accross multiple lines appear to be a CR (carriage return) instead of '\n'. The filename is being diaplayed in thetitle of a text editor with %0D in the positions of where the file name breaks up. So I need to remove the CR chars from my filenames.

Best Answer

Try with rename:

find /path/to/dir -exec rename -n 's/\n/_/' {} \+

Remove -n to actually rename the files.

Related Question