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 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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s