coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Some question regarding tail and option "-c"


From: Bob Proulx
Subject: Re: Some question regarding tail and option "-c"
Date: Wed, 3 Oct 2012 11:18:59 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

Robert Milasan wrote:
> Hello, I think I found an issue, but not sure if it's a bug or
> feature :)

That is always the hardest question!  :-)

> When using option "-c" from tail there are 3 ways, two working and one
> not:
> 
> 1. cat /etc/passwd|tail -c 10 (doesn't work)
> 2. cat /etc/passwd|tail -c -10 (works)
> 3. tail -c 10 /etc/passwd (works)
> 
> Why does the option 2 and 3 work, but the first one doesn't?

All three work for me.  But I suspect that the compile time choices on
your system are different and the choices on mine and cause the
program to use a different set of system calls.  Someone else may know
the problem off the top of their head.  Such as not being able to seek
when reading from a pipe.  Which is the usual reason.

What version of tail are you using?

  tail --version

I think the easiest way to see what is happening at run time is to use
strace.  Install it if you don't have it.  Then run:

  cat /etc/passwd | strace -v -o tail.strace tail -c 10

That should produce about a 14K output file with all of the system
calls logged.

Warning: This may contain information that you don't want to share and
these mailing lists are public and archived many public places.  You
should pick something you don't mind sharing for your source material.

Mine says:

  ...
  read(0, "root:x:0:0:root:/root:/bin/bash\n"..., 8192) = 2894
  read(0, "", 8192)                       = 0
  fstat(1, {st_dev=makedev(0, 10), st_ino=9, st_mode=S_IFCHR|0620, st_nlink=1, 
st_uid=1000, st_gid=5, st_blksize=1024, st_blocks=0, st_rdev=makedev(136, 6), 
st_atime=2012/10/03-11:11:29, st_mtime=2012/10/03-11:11:29, 
st_ctime=2012/08/24-17:06:52}) = 0
  mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 
0x7ff0f7061000
  write(1, "bin/false\n", 10)             = 10
  ...

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]