Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
In my current unix server, if I need to tail the last line of a file, I need to type tail -0 <filename> as opposed to tail -1 <filename>. I'm wondering if it is because of the Linux kernel version. Do different shells have different behavior, e.g. Korn Shell and Bash.
It's probably due to your version of tail. Does your tail not have the -n flag? That's generally what I use:
Code:
tail -n 1 <filename>
tail -n 0 also gives me the same result. So there's no difference using -n flag or not. If I type tail -n 1 <filename>, it will gives me last two lines.
I'd imagine they'd all be 0 and it is most likely determined by command itself. The only difference would most likely be how lines are determined. Not to mention most programming counters start w/0, unless purposefully skipped.
What distro are you using and what is your version of tail?
Code:
tail --version
I've tried on RHEL 4 (tail 5.2.1), OpenSUSE 11.4 (tail 8.9), every Fedora from 4 to 15 (tail 5.2.1 to 8.10), and cygwin with tail 6.10, and can't reproduce that behavior.
Last edited by suicidaleggroll; 11-16-2011 at 11:30 AM.
What distro are you using and what is your version of tail?
Code:
tail --version
I've tried on RHEL 4 (tail 5.2.1), OpenSUSE 11.4 (tail 8.9), every Fedora from 4 to 15 (tail 5.2.1 to 8.10), and cygwin with tail 6.10, and can't reproduce that behavior.
I'd imagine they'd all be 0 and it is most likely determined by command itself. The only difference would most likely be how lines are determined. Not to mention most programming counters start w/0, unless purposefully skipped.
The file lines are ended by unix end line as normal. I tried "head -0 <filename>" which gives me nothing and "head -1 <filename>" gives me the first line.
The differences are mostly due to the source of the basic system utilities, rather than the shell* or the system.
I believe most of the traditional flavors of Unix provide their own home-spun implementations of the basic core utilities, while Linux distros pretty much all use the ones written by the gnu organization.
While the command names and basic posix-defined functions should be the same across all *nixes, they can sometimes be quite different in their operating details and the exact mix of features they support. The gnu ones in particular have often been greatly expanded with additional features not available elsewhere (e.g. the -i in-file-editing option in sed).
*Although there are syntax differences between bash and ksh, for example, each shell will generally work the same across all platforms, barring the occasional feature that isn't supported by some underlying system.
Edit: Here are the manpage for aix and the gnu documentation, so you can compare their features. They don't appear to say anything about using 0 vs 1, however.
Hmmmm interesting about head. If I think about it -- it probably uses Line 0 POS 0 = 0 Where as if fully reversed Line 0 POS EOF = 0. Which would make sense head vs tail.
Hmmmm interesting about head. If I think about it -- it probably uses Line 0 POS 0 = 0 Where as if fully reversed Line 0 POS EOF = 0. Which would make sense head vs tail.
Except that with head/tail you aren't telling it to print "line 1", you're telling it to print "1 line". Big difference. Telling it to print "0 lines" is nonsense and shouldn't do anything (which it doesn't on any GNU version of tail). It sounds like the version of tail he's working with has a bug, or maybe the developer of it just has a different interpretation of "print 0 lines" and "print 1 line" than the rest of the world.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.