Recursively adjust line endings for a bunch of files

Today I was importing a huge multi-module project into an SVN repository and every now and then it would come across a file that had an incorrect line ending set and abort with:
svn: Inconsistent line ending style

On the smaller modules it was fine as I’d just go into that directory and flip -u filename[1] the line endings. It was on the modules that took up to an hour to import, and then fail that annoyed me. Yeah great, thanks for that. Don’t offer to fix it or skip it or anything, just abort. Real helpful.

Fed up with wasting time, I put together a command that will descend into a directory recursively and flip everything that matches the extensions given. You can add more extensions as you please.

find . \( -name "*.js" -o -name "*.css" -o -name "*.properties" -o -name "*.xml" -o -name "*.html" -o -name "*.java" -o -name "*.jsp" \) -type f -exec flip -u '{}' \; -print

It’s important not to use flip on binary files as the same characters in binary (0x0a and 0x0d) do not necessarily mean new lines and they can be corrupted. So ensure you only flip text-based files.


[1] flip.cpp can be grabbed from https://ccrma.stanford.edu/~craig/utility/flip/flip.cpp and compiled with g++. Then just put it in /usr/local/bin or similar directory on your path.

One thought on “Recursively adjust line endings for a bunch of files

Leave a comment