在 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
这样,你就可以根据需要恢复或替换文件的换行符了。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:linux替换换行符为何失败