Friday, 2 November 2012

Grep:Search Multiple Words Using grep Command


Using grep Command


In this example, search warning, error, and critical words in a text log file called /var/log/messages, enter:

[root@new-host sankar]# cat /var/log/messages |grep error
Oct 31 15:52:32 new-host kernel: usb 1-1: device not accepting address 5, error -71

[root@new-host sankar]# grep 'warning\|error\|critical' /var/log/messages
Oct 31 15:52:32 new-host kernel: usb 1-1: device not accepting address 5, error -71
[root@new-host sankar]#

To just match words, add -w swith:

MySQL:List of non-empty tables in mysql database


List of non-empty tables in mysql database


Use database 'information_schema' and run
SELECT * FROM `TABLES` WHERE `TABLE_ROWS` > 0 
this will give you all non-empty tables in the server for a certain database run
SELECT * FROM `TABLES` WHERE `TABLE_ROWS` > 0  AND `TABLE_SCHEMA` = 'database_name'

To select from a selective database, you can filter by column TABLE_SCHEMA
select table_schema, table_type, table_name 
from information_schema.tables where table_rows>=1;