Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've come across the command line "tail -f log/[environment_name]" but, unfortunately, I've got no idea on how to use it and how it can do some good for me?

Can anyone please shed some light on me on how and when I can use this command? Any full explanation would be really appreciated.

share|improve this question

migrated from stackoverflow.com Nov 8 '11 at 5:28

This question came from our site for professional and enthusiast programmers.

add comment

4 Answers 4

It continuously updates the output of the log file to the console in Unix-like environments (Linux, OS X, Cygwin in Windows).

tail -f log/development.log

This will keep the development log scrolling in your console/command window.

The -f stands for "follow". See the tail man page for more details.

share|improve this answer
add comment

From a sysadmin perspective, it can be useful to see log entries as they appear. This can help when troubleshooting services such as email (SMTP), web (Apache), etc. as one can see exactly when entries appear relative to the firing of various events.

Another useful, related command is watch which will repeat a command a specified intervals, refreshing the screen for each repeat. For example, you can watch a file listing to monitor file sizes as they grow. Or monitor the status of a device such as a fax modem in a Hylafax installation.

share|improve this answer
add comment

There is also tailf, which does exactly the same as tail -f and is shorter to type. Yeah, I'm lazy. Tell me when you typed tail -f the 100th time.

It's commonly used to "follow" a log or other constant output, to see "what's hapenning" in real time.

share|improve this answer
1  
What distribution are you using? I do not have tailf on Mac OS X 10.7 unless I define an alias myself. –  William Jackson Nov 8 '11 at 12:39
    
Linux. It's in most Linuxes, as it comes in the util-linux package. –  ata Nov 9 '11 at 0:53
    
There's also a functional difference, I quote man tailf: "It is similar to tail -f but does not access the file when it is not growing. This has the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically when no log activity is happening." –  mpy Apr 17 '13 at 11:16
add comment

Normally, a program such as cat terminates when the read() system call first returns 0 bytes of data, treating it as EOF (end of file). Normally, the tail program does the same; without the -f option, it finds the end of the file and reads backwards to find the last 10 (by default) lines. ('Reads backwards' means 'seeks backwards and reads some data'.)

When the -f (follow) option is used, the tail command recognizes the 0 byte return, but does not terminate. Instead, it goes to sleep for a short period, and then tries to read some more data. If the file is a log file that is growing as a process (for example, a web server or database server) writes more information, then tail -f will show the extra information more or less as it appears.

Another use for this is on long-running compilations. You set the compilation running in the background and writing its output to a log file. In the foreground, you run tail -f on the log file, and when you spot a problem, you can interrupt the tail without breaking the compilation.

share|improve this answer
add comment

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.