Книга: Fedora™ Unleashed, 2008 edition
Printing the Last Lines of a File with tail
Printing the Last Lines of a File with tail
If you want to watch a log file as it is written to, or want to monitor a user's actions as they are occurring, you need to be able to track log files as they change. In these situations, you need the tail
command, which prints the last few lines of a file and updates as new lines are added. This command tells tail
to print the last few lines of /var/log/httpd/access_log
, the Apache hit log:
$ tail /var/log/httpd/access_log
To get tail
to remain running and update as the file changes, add the -f
parameter (which means "follow"):
$ tail -f /var/log/httpd/access_log
You can tie the lifespan of a tail
call to follow the existence of a process by specifying the --pid
parameter. When you do this, tail
continues to follow the file you asked for until it sees that the process (identified by PID) is no longer running, at which point tail
stops tailing.
If you specify multiple files on the command line, tail
follows both, printing file headers whenever the input source changes. Press Ctrl+C to terminate tail
when in follow mode.
- Printing the Contents of a File with cat
- Changing Directories with cd
- Changing File Access Permissions with chmod
- Copying Files with cp
- Printing Disk Use with du
- Finding Files by Searching with find
- Searches for a String in Input with grep
- Paging Through Output with less
- Creating Links Between Files with ln
- Finding Files from an Index with locate
- Listing Files in the Current Directory with ls
- Reading Manual Pages with man
- Making Directories with mkdir
- Moving Files with mv
- Listing Processes with ps
- Deleting Files and Directories with rm
- Printing the Last Lines of a File with tail
- Printing Resource Usage with top
- Printing the Location of a Command with which
- Shared Cache file
- Безопасность внешних таблиц. Параметр EXTERNAL FILE DIRECTORY
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Chapter 13. rc.firewall file
- Appendix A. Detailed explanations of special commands
- Appendix E. Other resources and links
- Example NAT machine in theory
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- The final stage of our NAT machine
- Compiling the user-land applications