Convert line-endings for whole directory tree (Git)
dos2unix does that for you. Fairly straight forward process.dos2unix filename
Thanks to toolbear, here is a one-liner that recursively replaces line endings and properly handles whitespace, quotes, and shell meta chars.
find . -type f -exec dos2unix {} \;
If you're using dos2unix 6.0 binary files will be ignored.
How can I make all line endings (EOLs) in all files in Visual Studio Code, Unix-like?
In your project preferences, add/edit the following configuration option:
"files.eol": "\n"
This was added as of commit 639a3cb, so you would obviously need to be using a version after that commit.
Note: Even if you have a single CRLF
in the file, the above setting will be ignored and the whole file will be converted to CRLF
. You first need to convert all CRLF
into LF
before you can open it in Visual Studio Code.
See also: https://github.com/Microsoft/vscode/issues/2957
Change EOL on multiple files in one go
The Replace dialog can handle extended characters like EOL. Just change "Search Mode" to "Extended", and you can work with EOL (\r\n in Windows or \n in Unix), tabs (\t), etc.
You can also use the Find in Files tab of the dialog to do the replace across multiple files.
Recursively convert DOS files to UNIX format in Python
Recursively for all files in the dosdir directory.
import os
os.system("find dosdir -type f -exec dos2unix -u {} \; ");
requires the find and dos2unix system commands, mostly this is true by default.
Convert DOS line endings to Linux line endings in Vim
dos2unix is a commandline utility that will do this, or :%s/^M//g
will if you use Ctrl-v Ctrl-m to input the ^M, or you can :set ff=unix
and Vim will do it for you.
There is documentation on the fileformat setting, and the Vim wiki has a comprehensive page on line ending conversions.
Alternately, if you move files back and forth a lot, you might not want to convert them, but rather to do :set ff=dos
, so Vim will know it's a DOS file and use DOS conventions for line endings.
Related Topics
Gcc: Putchar(Char) in Inline Assembly
A Modification to %Esp Cause Sigsegv
Qt Development on Linux Using Eclipse
Pipe Bash Command Output to Stdout and to a Variable
Best Way Elevate the Privileges Programmatically Under Different Versions of Linux
Bash, Linux, Need to Remove Lines from One File Based on Matching Content from Another File
Git Diff with Line Numbers and Proper Code Alignment/Indentation
Abuse Curl to Communicate with Redis
What's the Difference Between "Env" and "Set" (On MAC Os X or Linux)
How to Create Virtual Ethernet Devices in Linux
Using Iconv to Convert from Utf-16Le to Utf-8