/etc/init.d/rcS 导致无法进入系统

使用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环境中已经有 dos2unixunix2dos命令

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...
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值