免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1508 | 回复: 7
打印 上一主题 下一主题

[文件系统] 一个关于回车键的比较弱智的问题 [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-16 09:50 |只看该作者 |倒序浏览
在Linux 下 文本文件中按回车键时是输入的ascii的\n吗,我试了一下,怎么好像不是:
下面是我操作的过程:
用vim新建b.dat,然后输入一个回车,保存退出
用hexdump -C b.dat 查看:

为什么有两个\n?

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
2 [报告]
发表于 2013-01-16 10:09 |只看该作者
zi ji ding ....

论坛徽章:
4
酉鸡
日期:2014-03-21 23:19:50狮子座
日期:2014-08-01 22:11:40酉鸡
日期:2015-01-10 21:31:442015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2013-01-16 11:13 |只看该作者
没啥吧,肯定是kernel自动给加了一个回车呗.

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
4 [报告]
发表于 2013-01-16 11:15 |只看该作者
那kernel为什么要再加一个呢?想不太明白

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
5 [报告]
发表于 2013-01-16 12:59 |只看该作者
还有一个文件结束符
你不输入回车,写入一个字符的话,里面一样会有的

论坛徽章:
2
CU十二周年纪念徽章
日期:2013-10-24 15:41:34处女座
日期:2013-12-27 22:22:41
6 [报告]
发表于 2013-01-16 13:27 |只看该作者
VIM自己加的,可能unix下有“所有文件文件必需以换行结尾”的惯例。

# echo -n a > /tmp/abc
# hexdump /tmp/abc
0000000 0061                                   
0000001

#vi /tmp/abc

提示

"/tmp/c" [noeol] 1L, 1C

此时只是进入插入模式,什么也不做就退出,也会新加一个换行。

论坛徽章:
2
CU十二周年纪念徽章
日期:2013-10-24 15:41:34处女座
日期:2013-12-27 22:22:41
7 [报告]
发表于 2013-01-16 13:29 |只看该作者
:h noeol

                              'endofline' 'eol' 'noendofline' 'noeol'
'endofline' 'eol'       boolean (default on)
                              local to buffer
                             {not in Vi}
        When writing a file and this option is off and the 'binary' option
        is on, no <EOL> will be written for the last line in the file.  This
        option is automatically set when starting to edit a new file, unless
        the file does not have an <EOL> for the last line in the file, in
        which case it is reset.  Normally you don't have to set or reset this
        option.  When 'binary' is off the value is not used when writing the
        file.  When 'binary' is on it is used to remember the presence of a
        <EOL> for the last line in the file, so that when you write the file
        the situation from the original file can be kept.  But you can change
        it if you want to.

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
8 [报告]
发表于 2013-01-16 14:31 |只看该作者
谢谢各位,明白了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP