Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This is what I did using tail command. When I try to output the file to screen the file is empty.

~]$ tail > AFS2F1
PASSES ALL DATA FROM INPUT TO OUTPUT
PASSES ONLY SPECIFIED COLUMNS
PASSES NUMBER OF SPECIFIED LINES AT BEGINNING
COMBINES COLUMNS
ARRANGES DATA IN SEQUENCE
PASSES NUMBER OF SPECIFIED LINES AT THE END OF DATA
TRANSLATES ONE OR MORE CHARACTERS
DELETES DUPLICATE LINES
COUNTS CHARACTERS, WORDS, OR LINES
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Is there anything wrong with the way I'm using tail command?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

tail will only output the last 10 lines. So one way or another, you'll have to tell it you've finished typing so it knows what lines (the 10 last ones) to output.

If you press CTRL-C (the default intr character on most systems) a SIGINT signal will be sent to it which will kill it. Because it had not seen the end of input by the time you killed it, it will not have had the opportunity to write anything yet, so it will die without having output anything.

The terminal way to signify the end of input (when the terminal is in canonical mode) is to enter the eof character (by default Ctrl-D on most systems) on an empty line.

Then tail will detect that the end of input is being reached and will output the 10 last lines that it has received.

share|improve this answer
    
thank I did pressed CTRL-C instead of Ctrl-D –  user1763658 Feb 25 '13 at 21:46

Yes, you should provides a input to tail, so :

tail file > newfile

If you want to use STDIN :

cat file | tail > newfile

or

 head > new_file < file

or

tail > AFS2F1<<EOF
PASSES ALL DATA FROM INPUT TO OUTPUT
PASSES ONLY SPECIFIED COLUMNS
PASSES NUMBER OF SPECIFIED LINES AT BEGINNING
COMBINES COLUMNS
ARRANGES DATA IN SEQUENCE
PASSES NUMBER OF SPECIFIED LINES AT THE END OF DATA
TRANSLATES ONE OR MORE CHARACTERS
DELETES DUPLICATE LINES
COUNTS CHARACTERS, WORDS, OR LINES
ABCDEFGHIJKLMNOPQRSTUVWXYZ
EOF
share|improve this answer
    
Then how do i use tail to create a file from stdin? The way I did above was similar for cat command so i thought i would work –  user1763658 Feb 25 '13 at 21:41
1  
tail > file is perfectly fine if the user wants to type a bunch of stuff on stdin and save the last 10 lines into the file. –  glenn jackman Feb 25 '13 at 21:46
    
See my edited post –  sputnick Feb 25 '13 at 21:49
1  
Thou shalt not use cat(1) in vain. –  vonbrand Feb 25 '13 at 21:55

The problem is that tail program buffers its input file until it get a eof condition, then it prints out the last lines (10 by default). Most likely you are interrupting it with ctrl-c combination that terminates it, thus the tail has no chance to print out the collected lines. If you use ctrl-d instead then you effectively send the end-of-file character to the tail's input stream, so it will print out the lines collected.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.