免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 9198 | 回复: 15

关于tail命令的问题? [复制链接]

论坛徽章:
0
发表于 2008-07-07 20:09 |显示全部楼层
我的系统是fedora8,用tail命令我加+3选项时.命令会把+3当成一个文件名,而不是实现重第三行打印到最后.
请问你们有这种情况吗?

论坛徽章:
0
发表于 2008-07-07 20:16 |显示全部楼层
原帖由 argstormsky 于 2008-7-7 20:09 发表
我的系统是fedora8,用tail命令我加+3选项时.命令会把+3当成一个文件名,而不是实现重第三行打印到最后.
请问你们有这种情况吗?


下次-3就不会了!

论坛徽章:
0
发表于 2008-07-07 20:59 |显示全部楼层
请看7楼。。。。。。

[ 本帖最后由 世上最废的人 于 2008-7-8 10:02 编辑 ]

论坛徽章:
0
发表于 2008-07-07 21:21 |显示全部楼层
因为这个!
-n, --lines=N
              output the last N lines, instead of the last 10

论坛徽章:
0
发表于 2008-07-07 21:27 |显示全部楼层
原帖由 志国 于 2008-7-7 21:21 发表
因为这个!
-n, --lines=N
              output the last N lines, instead of the last 10


你的回答真的有点答非所问。
你那个-n只能显示最后n行,根本满足不了LZ的需求。

-n, --lines=N
              output the last N lines, instead of the last 10
是个人都会看man,不劳您费这个心。

论坛徽章:
0
发表于 2008-07-07 23:17 |显示全部楼层
我看了man手册的.上面说-n就是打印出倒数n行,而+n就是从顺数n行打印到最后.可是我用命令tail +3 peom,tail会把"+3"当作文件名.不知道为什么?shell 难道不能把+3转换为tail的参数传给tail吗?

论坛徽章:
0
发表于 2008-07-08 00:17 |显示全部楼层
原帖由 argstormsky 於 2008-7-7 20:09 發表
我的系統是fedora8,用tail命令我加+3選項時.命令會把+3當成一個文件名,而不是實現重第三行打印到最後.
請問你們有這種情況嗎?


tail +3 這個用法已經被廢棄了,因為實際上若檔名真的是 +3 時候不是真的有問題呢 ?

若你要這樣使用,您可以改成相容舊式語法。

  1. export _POSIX2_VERSION=199209
复制代码


若你要知道明確文件說明,請看這段文件:



  1. File: coreutils.info,  Node: Standards conformance,  Prev: Special built-in utilities,  Up: Common options

  2. 2.9 Standards conformance
  3. =========================

  4. In a few cases, the GNU utilities' default behavior is incompatible
  5. with the POSIX standard.  To suppress these incompatibilities, define
  6. the `POSIXLY_CORRECT' environment variable.  Unless you are checking
  7. for POSIX conformance, you probably do not need to define
  8. `POSIXLY_CORRECT'.

  9.    Newer versions of POSIX are occasionally incompatible with older
  10. versions.  For example, older versions of POSIX required the command
  11. `sort +1' to sort based on the second and succeeding fields in each
  12. input line, but starting with POSIX 1003.1-2001 the same command is
  13. required to sort the file named `+1', and you must instead use the
  14. command `sort -k 2' to get the field-based sort.

  15.    The GNU utilities normally conform to the version of POSIX that is
  16. standard for your system.  To cause them to conform to a different
  17. version of POSIX, define the `_POSIX2_VERSION' environment variable to
  18. a value of the form YYYYMM specifying the year and month the standard
  19. was adopted.  Two values are currently supported for `_POSIX2_VERSION':
  20. `199209' stands for POSIX 1003.2-1992, and `200112' stands for POSIX
  21. 1003.1-2001.  For example, if you have a newer system but are running
  22. software that assumes an older version of POSIX and uses `sort +1' or
  23. `tail +10', you can work around any compatibility problems by setting
  24. `_POSIX2_VERSION=199209' in your environment.

复制代码


--

评分

参与人数 1可用积分 +9 收起 理由
零二年的夏天 + 9 精品文章

查看全部评分

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
发表于 2008-07-08 00:27 |显示全部楼层
man tail
info tail

论坛徽章:
0
发表于 2008-07-08 09:57 |显示全部楼层
总结帖:tail +n 不是新版的posix标准.
解决方法在七楼.

论坛徽章:
0
发表于 2008-07-10 12:33 |显示全部楼层
[root@localhost ~]# cat test.txt
1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# tail -n +3 test.txt
3
4
5
6
7
8
9
10
11
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP