1

被Windows编辑过的Linux文件恢复

 2 years ago
source link: https://zhangyiming748.github.io/post/bei-windows-bian-ji-guo-de-linux-wen-jian-hui-fu/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

被Windows编辑过的Linux文件恢复

2022-09-04 Windows Linux

错误文本:解释器错误:没有那个文件或目录

Windows下,默认的文件编译,每一行的结尾是\n\r但是在Linux下文件的结尾是\n
因此在Windows环境下编辑过的文件在Linux下打开看的时候每一行的结尾就会多出来一个字符\r
常规只是看看文件的情况下,一般没啥影响,但是执行命令解释器解析的时候,就会出现本文中的异常
解决方法 sed -i 's/\r$//' build.sh

彻底解决方法:

dos2unix是将Windows格式文件转换为Unix\Linux格式的实用命令.Windows格式文件的换行符为\r\n 而Unix&Linux文件的换行符为\ndos2unix命令其实就是将文件中的\r\n 转换为\n
而unix2dos则是和dos2unix互为孪生的一个命令,它是将Linux&Unix格式文件转换为Windows格式文件的命令
dos2unix 可以一次转换多个文件
find -name "*.sh" -exec dos2unix {} \;

0 comments
Error: Not Found.

Be the first person to leave a comment!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK