Searching for a string inside multiple files and output the name of the files containing that string

find . -name “*” | grep -i ecomm | xargs ls -las | grep “Aug 27” | awk ‘{print $10}’ | xargs grep -i string_to_search_for | grep -i “\.log” | awk ‘{print $1}’

where:

“ecomm” is part of the name of the file in which we should search for the string
“Aug 27” is the date the files were last modified
“$10” is the last column resulting from the “ls -las” command, this is the column containing the filename (the string is not searched for yet)
“string_to_search_for” the name is obvious 🙂
“\.log” all the files end with “.log”
“$1” is the filename containing the string

There are still two problems left (I don’t have time right now to solve them):
  1. All the filenames end with the “:” character, it needs to be omitted
  2. Filenames are redundant, i.e. each file is repeated many times

Update: Problem number 2 solved using the “sort” and “uniq” commands which sort the results and then omit the repeated results, here is an example:

find . -name “*” | grep -i ecomm | xargs ls -las | grep “Aug 31” | awk ‘{print $10}’ | xargs grep -i mbassiouny | grep -i “\.log” | awk ‘{print $1}’ | sort | uniq

Tagged , | Leave a comment

How to fix Java plugin in Firefox (DRAFT)

sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.14/jre/plugin/i386/ns7/libjavaplugin_oji.so

aamr@aamr-laptop:/usr/lib/firefox-3.5.4pre/plugins$ sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.14/jre/plugin/i386/ns7/libjavaplugin_oji.so
4 lrwxrwxrwx 1 root root 73 2009-08-27 11:52 libjavaplugin_oji.so -> /usr/lib/jvm/java-6-sun-1.6.0.14/jre/plugin/i386/ns7/libjavaplugin_oji.so

Tagged , | Leave a comment

Killing a process that listening on a port

Sometimes you may want to stop a server application that is running on a pre-defined port number.

lets give an example; if you have a tomcat server running on port 8080, you don’t have the process number to execute the kill command, and you don’t want to go through the ps hell.

here’s what you should do to stop (kill) the tomcat process:

first, make sure that the server is running on that port :
netstat -nap | grep 8080

then, kill the process that is running on that port using this command:
fuser -k 8080/tcp

this will kills the process that listens on port 8080

note: the fuser binary resides in different places based on your linux distribution. So, to find its exact binary location, uses this command:
whereis fuser

Tagged , | Leave a comment

Highlight your grep results

Used grep command before ?
grep is a very good command that allows you to grep text 🙂
It allows you to search the contents of a file/group of files for a string (regular expression)

of course it is great, but the output may be somewhat confusing !!!!

so, try this:
alias grep=’grep –color=always’
then try to use grep, you will see the output contains the string you search for is highlighted.

try to put this command in your .bashrc file in order not to re-alias it each time, like that :
echo “alias grep=’grep –color=always'” >> ~/.bashrc

Tagged | Leave a comment

Print the exact contents for a file

If you want to print the exact contents of a file (the white spaces, the new lines), use this command:

more file_name | od -c

Tagged , | Leave a comment