Class Notes on: April 4, 2015

§  tail -f access.log | grep 24.10.160.10

This is a useful example of using tail and grep to selectively monitor a log file in real time.
In this command, tail monitors the file access.log. It pipes access.log's final ten lines, and any new lines added, to the grep utility. grep reads the output from tail, and outputs only those lines which contain the IP address 24.10.160.10.

§ 

///////////////////////// ADD ON / start - 21 March 2015 /////////////////

reference: http://www.cyberciti.biz/faq/linux-log-files-location-and-how-do-i-view-logs-files/

Common Linux log files names and usage

·  /var/log/messages : General message and system related stuff

·  /var/log/auth.log : Authenication logs

·  /var/log/kern.log : Kernel logs

·  /var/log/cron.log : Crond logs (cron job)

·  /var/log/maillog : Mail server logs

·  /var/log/qmail/ : Qmail log directory (more files inside this directory)

·  /var/log/httpd/ : Apache access and error logs directory

·  /var/log/lighttpd/ : Lighttpd access and error logs directory

·  /var/log/boot.log : System boot log

·  /var/log/mysqld.log : MySQL database server log file

·  /var/log/secure or /var/log/auth.log : Authentication log

·  /var/log/utmp or /var/log/wtmp : Login records file

·  /var/log/yum.log : Yum command log file.

////////////////////////// ADD ON / End - 21 March 2015 //////////////////////

è  head : This command is opposite of tail command. It displays the 1st ten lines of a text file

§  Examples:

§  head -15 myfile.txt (Displays the 1st 15 lines of my text file)

·  head /etc/passwd (Displays the 1st 10 lines of passwd file)

§ 

è  less : This command will open a plain-text file viewer to view the file.

§  Just a little different than the other commands… you can browse the file using the “Page Down Key”, “Page Up Key”, or “spacebar”

§  Example: less file.txt (views the file “file.txt”) / less –N file.text (displays a line # at beginning of each line)

§  Offers a search capability: Ex: less -I -p "example" message [ to find "example" in the file. ]

§  To Quit “less”, use “q”

è  more : This command is a filter for paging through text one screen at a time. It does not provide as many options or enhancements as less, but is nevertheless quite useful and simple to use.

§  Examples:

§  more +3 myfile.txt (Display the contents of file myfile.txt, beginning at line 3.)

§  more +/”hope” myfile.txt (Display the contents of file myfile.txt, beginning at the first line containing the string "hope". )

§  ls | more (List the contents of the current directory with ls, using more to display the list one screen at a time. )

Exercise: Working with File contents (cat, tac, more, less, tail, head):