【问题标题】:Is "tail +2" supported by Linux?Linux是否支持“tail +2”?
【发布时间】:2011-05-31 09:26:55
【问题描述】:

我注意到tail +2在Solaris ksh中是支持的,但是在Red Hat Linux中会出现错误:

c008>> ps -p 4009,6282,31401,31409 | tail +2
tail: cannot open `+2' for reading: No such file or directory

在 Solaris 中,

bjbldd>> ps -p 2622,16589,11719,846 |tail +2
16589 ??       0:00 xterm
  846 pts/180  0:00 cscope
11719 pts/180  0:00 cscope
2622 pts/114  0:00 apxcscop

PID TTY TIME CMD这一行被“tail +2”排除。

我知道grep -v PID 会起作用。但是不知道Linux tail 有没有类似的选项?

【问题讨论】:

    标签: tail


    【解决方案1】:

    来自tail(1)

       -n, --lines=K
              output the last K lines, instead of the last 10; or
              use -n +K to output lines starting with the Kth
    

    所以试试-n +2--lines=+2

    $ ps -p 20085 9530 29993 2069 2012 | tail -n +2
     2012 ?        Sl     0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
     2069 ?        S      0:00 /usr/bin/dbus-launch --exit-with-session i3
     9530 ?        Sl     0:01 /usr/lib/udisks/udisks-daemon
    20085 ?        S      0:00 /usr/sbin/apache2 -k start
    29993 ?        S      0:00 [kworker/1:0]
    $ 
    

    【讨论】:

      【解决方案2】:

      我熟悉 Solaris 上的 tail +2 语法,但它似乎不适用于 Ubuntu。

      超级用户的这个回答似乎有效:

      tail --lines=+100 <file> 
      

      来源:https://superuser.com/questions/62970/unix-cat-starting-from-line

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-13
        • 2017-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多