使用putty 和 pscp 自制了一个生产脚本,脚本中从windows复制程序和启动文件至linux系统中,系统重启后,提示如下信息,找不到 /etc/init.d/rcS
文件
can't run '/etc/init.d/rcS': No such file or directory
can't open /dev/ttyO0: No such file or directory
can't open /dev/ttyO0: No such file or directory
can't open /dev/ttyO0: No such file or directory
can't open /dev/ttyO0: No such file or directory
最后查找原因是在git提交时,把脚本的换行符由LF改为了CRLF
导致Linux不能识别/etc/init.d/rcS文件
使用dos2uninx命令转换换行符后解决。
关于CRLF、CR、LF的解释:
- CR:Carriage Return,对应ASCII中转义字符,
\r
,表示回车 - LF:Linefeed,对应ASCII中转义字符,
\n
,表示换行 CRLF - CRLF:Carriage Return & Linefeed,
\r\n
,表示回车并换行
Windows操作系统采用两个字符来进行换行,即CRLF
Unix/Linux/Mac OS X操作系统采用单个字符LF来进行换行
另外,MacIntosh操作系统(即早期的Mac操作系统)采用单个字符CR来进行换行。
批量转换编码格式:其中Linux 上可以用 dos2unix
指令直接转换,反之使用unix2dos
命令
在git bash环境中已经有 dos2unix
和 unix2dos
命令
name@win MINGW64 /
$ which dos2unix.exe
/usr/bin/dos2unix.exe
name@win MINGW64 /
$ which unix2dos.exe
/usr/bin/unix2dos.exe
$ dos2unix.exe -h -v
Usage: dos2unix [options] [file ...] [-n infile outfile ...]
--allow-chown allow file ownership change
-ascii convert only line breaks (default)
-iso conversion between DOS and ISO-8859-1 character set
-1252 use Windows code page 1252 (Western European)
-437 use DOS code page 437 (US) (default)
-850 use DOS code page 850 (Western European)
-860 use DOS code page 860 (Portuguese)
-863 use DOS code page 863 (French Canadian)
-865 use DOS code page 865 (Nordic)
-7 convert 8 bit characters to 7 bit space
-b, --keep-bom keep Byte Order Mark
-c, --convmode conversion mode
convmode ascii, 7bit, iso, mac, default to ascii
-f, --force force conversion of binary files
-h, --help display this help text
-i, --info[=FLAGS] display file information
file ... files to analyze
-k, --keepdate keep output file date
-L, --license display software license
-l, --newline add additional newline
-m, --add-bom add Byte Order Mark (default UTF-8)
-n, --newfile write to new file
infile original file in new-file mode
outfile output file in new-file mode
--no-allow-chown don't allow file ownership change (default)
-o, --oldfile write to old file (default)
file ... files to convert in old-file mode
-q, --quiet quiet mode, suppress all warnings
-r, --remove-bom remove Byte Order Mark (default)
-s, --safe skip binary files (default)
-u, --keep-utf16 keep UTF-16 encoding
-ul, --assume-utf16le assume that the input format is UTF-16LE
-ub, --assume-utf16be assume that the input format is UTF-16BE
-v, --verbose verbose operation
-F, --follow-symlink follow symbolic links and convert the targets
-R, --replace-symlink replace symbolic links with converted files
(original target files remain unchanged)
-S, --skip-symlink keep symbolic links and targets unchanged (default)
-V, --version display version number
dos2unix命令可以批量转换,可以自动跳过二进制文件
$ dos2unix.exe *
dos2unix: Skipping bin, not a regular file.
dos2unix: Binary symbol 0x01 found at line 1
dos2unix: Skipping binary file bridge
dos2unix: converting file cmdInstall.txt to Unix format...
dos2unix: converting file cmdRemove.txt to Unix format...
dos2unix: Skipping ext, not a regular file.
dos2unix: converting file xxt.bat to Unix format...
dos2unix: Skipping int, not a regular file.
dos2unix: converting file ReadMe.txt to Unix format...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)