Everybody knows :-) that in Windows plain text files lines are terminated with CR+LF, and in Unix&Linux - with LF only. How can I quickly convert all my source code files from one format to another and back?
That depends: if the files are under version control, this could be a rather unpopular history-polluting decision. Git has the option to automagically convert line endings on check-out.
If you do not care and want to quickly convert, there are programs like
There are several dedicated programs, including
Simply pick the tool for the appropriate direction and pass the names of the files to convert on the command line.
If you don't have either, but have Linux or Cygwin:
If you have perl:
With only POSIX tools (including BusyBox), to go from unix to dos, you'll need to pass the CR character literally in the sed command.
In the other direction, you can simply delete all CRs:
You can use wildcards to convert many files in the same directory at once, e.g.
To convert all files in the current directory and its subdirectories, if your shell is zsh, you can use
You can use
If you can only use the tools that require a redirection, use a
If you don't have
Here's a POSIX example. We tell
You can make the
winscp will also auto-convert, if told so.
If your files reside all in the same directory: