在 Linux 系统中,你可以使用 dos2unix 和 unix2dos 命令来转换文件的换行符
首先,确保你已经安装了 dos2unix。如果没有安装,可以使用以下命令安装:
对于基于 Debian 的系统(如 Ubuntu):
sudo apt-get install dos2unix
对于基于 RHEL 的系统(如 CentOS):
sudo yum install dos2unix
使用 dos2unix 命令将换行符从 CRLF(\r\n)转换为 LF(\n):
dos2unix inputfile outputfile
其中,inputfile 是你要转换的文件,outputfile 是转换后的文件。如果你想直接修改原文件,可以使用 -n 选项:
dos2unix -n inputfile inputfile
使用 unix2dos 命令将换行符从 LF(\n)转换为 CRLF(\r\n):
unix2dos inputfile outputfile
同样,如果你想直接修改原文件,可以使用 -n 选项:
unix2dos -n inputfile inputfile
这样,你就可以根据需要恢复或替换文件的换行符了。