Wednesday, August 17, 2011

How to Find Files Containing Search Terms on Ubuntu

To find files containing keywords, linux has a powerful command called grep, which you can use to find the lines inside any file or a list of files. I use this very often to find a function declaration in a set of php files that I’m unfamiliar with.
Let’s say we are looking for the definition of a function called wp_content_filterize, and we don’t know where to start. Let’s try using grep…
grep -r -i -n 'function wp_content_filterize' *
We should see the output right on the console
functions.php:18:function wp_content_filterize($thefilter) {
Now we know that the function definition is found in the file functions.php, on line 18.

Grep and punctuation marks

I've often tried to use grep to filter search results for locate and several times I've had to search for a string with locate:
locate svn
This search would obviously include all the '.svn' folders too. Trying to get rid with them with
locate svn | grep -v '.svn'
does not work, since grep uses basic regular expressions, and the period mark will simply match any character.

To explicitly indicate the usage of a punctuation mark, one has to put it in brackets. The statement will now look something like:
locate svn | grep -v '[.]svn'

I just scanned through the grep man pages, and everything is explained pretty clearly there. I'd recommend reading the bit on regular expressions.



Grep Recursively Through Single File Extension


You can use the following grep command to search through a directory, recursively, but only looking at a specific file pattern.

grep -r --include=<pattern> <string> <directory>
 
Here is an example that searches recursively starting at /home/joel/ and including only php files.

grep -r --include=*.php "public auction" ./
 
Other options you might want to add to the command:
-i Case insensitive match.
-c Count of matches; suppressing normal output. One line per file match.
-o Show only the part of a matching line that matches.
Here's another example with the -r, -i and -o options all added.

grep -rio --include=*.php "public auction" ./
 
linux/grep_recursively_through_single_file_extension.txt · Last modified: 2011/03/22 14:51 by Joel Dar


(SOURCES:  http://www.howtogeek.com/howto/ubuntu/find-files-containing-search-terms-on-ubuntu/ ,
http://www.joeldare.com/wiki/linux:grep_recursively_through_single_file_extension)

Thursday, July 14, 2011

How to Solve java.lang.OutOfMemoryError: PermGen space

When developing Java web apps and deploying it in Jetty, you might encounter the following problem:

java.lang.OutOfMemoryError: PermGen space
Exception in thread "Timer-1" java.lang.OutOfMemoryError: PermGen space
^CJava HotSpot(TM) Server VM warning: Exception java.lang.OutOfMemoryError occurred dispatching signal SIGINT to handler- the VM may need to be forcibly terminated


pressing ctrl+c or ctrl+d wouldn't stop or shutdown the application so i had to use:

ctrl+z

doing this stops it, but the java process was still running in the background so i ran this:

ps aux|grep java

to confirm and saw something like this:

myuser 16947 2.1 13.6 768992 279720 pts/0 Z 09:40 1:07 /home/myuser/Desktop/jre1.6.0_11/bin/java -Dprogram.name=run.sh -server -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true -Djava.endorsed.dirs=/usr/jboss/lib/endorsed -classpath /usr/jboss/bin/run.jar org.jboss.Main -b 0.0.0.0 -c myuser

to kill the process you just run something like this:

kill -9 java-process-id-number

so in this case:

kill -9 16947

then if you run this again:

ps aux|grep java

you'll see this:

[java]

i found that when i close the terminal window and then open a new terminal and run this again:
Code:

ps aux|grep java

(SOURCE: http://nickhumphrey.net/showthread.php?p=3248)

Wednesday, July 13, 2011

How to Cure Angular Cheilitis/Stomatitis -- Naturally

If you are experiencing red irritated skin at the corners of your mouth, then you have a skin condition known as Angular Cheilitis (aka Angular Stomatitis). You are not alone many people suffer from this and find it hard to engage in everyday activities. Such as social situations since there is always a fear of someone staring at you and seeing your flaw. And also having to worry about whether or not the corners of your mouth might start bleeding because of the excessive movement of your mouth. No one should live their life worrying about things like this. It causes setbacks, and makes you less confident then you actually are. But there is a cure.

Angular Cheilitis can be naturally cured by changing a few things you do. Such as using lip balm. Sure you might experience dry chapped lips also but you have to try your best to avoid any kind of lip balm. It only makes it worse from all the moisture getting into contact with your open wounds. Also keep the area as dry as you can. This allows for it to heal without any interference. Moisture will cause the area to crack and bleed, which will then leave you with the possibility of scars in the future. So try your hardest to avoid any moisture. Any foods high in acidic acid can also worsen the condition. So avoid things like grapefruit and oranges. The acidic acid will just burn and irritate the skin causing more redness.

Now by following and changing a few minor things in your life you will allow your skin to heal itself. And remember that all you need is a little effort you will start to see your skin clearing up.

(SOURCE: http://www.articlesbase.com/wellness-articles/angular-cheilitisthe-symptoms-and-cures-578512.html)

How to Play Angry Birds in Linux

...well, not actually.

For Linux users, you’ll have to settle for a clone rather than the actual game which is very close to the original game and its spirit. It does not really have those small birds, but all kinds of animals (sheep, pigs … etc).
Since the game is very similar to Angry Birds, you should not be hurt! This is a SWF which a developer has created using a small script that will run in the SWF flash player. If everything goes well, a directory will be created (and normally a shortcut, which i did not find) to make a game a little more accessible from the “desktop”.
First go to System–>Admin–>Synaptic Package Manager and install imagemagick. You can simply search for “imagemagick” then Mark it for Installation and Apply to install. Then open a console and type:

wget http://wine-launcher-creator.googlecode.com/hg/setupangryanimals.sh
chmod +x setupangryanimals.sh
./setupangryanimals.sh


Then let the script work … Then click on the shortcut if you’re lucky to have it, go to the directory. Angryanimals which contains everything required to complete the game. Use your browser to launch the SWF or type in console

cd .angryanimals/
./flashplayer angryanimals.swf


OR simply double click on the angryanimals.swf

(SOURCE: http://ubuntu-install.blogspot.com/2011/06/angry-birds-clone-for-linux.html)

How to Find and Remove Hidden .svn Folders in Ubuntu

To delete .svn folders recursively using the command line:

----------------------------------------
Warning: Before you use this command make sure you have changed to the correct directory where you want to apply this. example:
cd /mysvn/path/iwant/to/delete/svn/folders
----------------------------------------

find -name "\.svn" -exec rm -rf {} \;

Monday, July 11, 2011

How to Set Environment Variables in Linux (Ubuntu)

In my case, I want to set JAVA_HOME, M2_HOME and M2 which are used by the application "Maven 2".

First, go to your default home directory.

Then, open your .profile file using a text editor like gedit and add the following lines at the end

JAVA_HOME="your jdk directory path"
M2_HOME="your maven directory path"
M2="$M2_HOME/bin"
export JAVA_HOME
export M2_HOME
export M2
export PATH=$M2:$PATH

How to Install Java Jdk on Ubuntu 10.04 (Lucid)

Type the following in the command line:

sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-j
dk

Then, to see if it was successful type the following:

javac -version

To list all installed jdk version under Ubuntu / Debian Linux, enter:

dpkg --list | grep -i jdk


(SOURCE: http://happy-coding.com/install-sun-java6-jdk-on-ubuntu-10-04-lucid/)