在Linux中查看文件编码

    技术2022-07-17  80

     

    今天执行一个程序时报错:

    [root@localhost bin]# sh stop-server.sh stop-server.sh:行2: $'\r': 未找到命令 stop-server.sh:行18: $'\r': 未找到命令 stop-server.sh:行19: $'\r': 未找到命令 stop-server.sh:行26: 语法错误: 未预期的文件结尾

    原因是由于该文件是在Windows系统下编辑的,传到Centos环境下无法执行,需要改成unix文件格式。

    使用Vim打开文件,

    显示文件编码格式 :set fileencoding

     

    更改文件编码 :set encoding=utf-8 fileencodings=utf-8

    如果是windows系统下编辑的文件,需要转换成unix系统才能执行。

    查看文件格式 :set fileformat? 设置文件格式为 unix :set fileformat=unix

     

    Processed: 0.014, SQL: 9