Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "tail +2" supported by Linux?

Tags:

tail

I noticed that tail +2 is supported in Solaris ksh, but in Red Hat Linux, an error will occur:

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

While in 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

The line of PID TTY TIME CMD is excluded by "tail +2".

I know grep -v PID will work. But I wonder if there is similar options for Linux tail?

like image 651
boyang Avatar asked May 31 '11 09:05

boyang


2 Answers

From 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

So try -n +2 or --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]
$ 
like image 93
sarnold Avatar answered Sep 20 '22 06:09

sarnold


I was familiar with tail +2 syntax on Solaris, but it doesn't seem to work on Ubuntu.

This answer from super-user seems to work:

tail --lines=+100 <file> 

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

like image 25
Mike R Avatar answered Sep 22 '22 06:09

Mike R