Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

search with in Data displayed as a result of tail Operation?

Tags:

linux

I am working on a Java EE application where its logs will be generated inside a Linux server .

I have used the command tail -f -n -10000 MyLog It displayed last 1000 lines from that log file .

Now I pressed Ctrl + c in Putty to disconnect the logs updation ( as i am feared it may be updated with new requests and I will loose my data )

In the displayed result, how can I search for a particular keyword ?? (Used / String name to search but it's not working)

like image 865
user1253847 Avatar asked Apr 27 '12 11:04

user1253847


People also ask

What does the tail command do?

On Unix-like operating systems, the tail command reads a file, and outputs the last part of it (the "tail"). The tail command can also monitor data streams and open files, displaying new information as it is written. For example, it's a useful way to monitor the newest events in a system log in real time.

What is different in the output of tail and tail F?

tailf will print out the last 10 lines of a file and then wait for the file to grow. 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 periodi- cally when no log activity is happening.

What is tail in Unix command?

FILE]... Tail is a command which prints the last few number of lines (10 lines by default) of a certain file, then terminates. Example 1: By default “tail” prints the last 10 lines of a file, then exits. tail /path/to/file.


2 Answers

Two ways:

tail -n 10000 MyLog| grep -i "search phrase"

tail -f -n 10000 MyLog | less

The 2nd method will allow you to search with /. It will only search down but you can press g to go back to the top.

Edit: On testing it seems method 2 doesn't work all that well... if you hit the end of the file it will freeze till you ctrl+c the tail command.

like image 200
dwurf Avatar answered Nov 16 '22 01:11

dwurf


Pipe your output to PAGER.

tail -f -n LINE_CNT LOG_FILE | less

then you can use

/SEARCH_STRING
like image 45
tuxuday Avatar answered Nov 16 '22 02:11

tuxuday