Thursday, June 25, 2009

find command - search content of a file

find in Unix is a very powerful tool for users which give you a very good flexibility. find command has a very broad usage among users. Here is the way how you can use find command to search files and content within files.

In order to search for a particular file named "test.txt" in /home directory, use
find /home -name "test.txt" -print
Search all the .txt files in /home directory, use
find /home -name "*.txt" -print
if you want to search for a string through all the files .txt files, there are two ways
find /home -name "*.txt" -exec grep -q "string-to-be-searched" '{}' \; -print
find /home -name "*.txt" | xargs grep "string-to-be-searched"
second one is more fast and efficient. Removal of -q in the first command will output the text segment where the specified string is. If you want to search all files for the string, just remove -name "*txt" option.

How to Increase JVM(Java) Heap Size

If you're building a big project using ant/maven then your jvm heap size may not sufficient and give you a java.lang.OutOfMemoryError: PermGen space exception. Increasing of maven/ant heap size might not sufficient enough for that and an increase of jvm heap size might also needed. When you're starting an application through command line, you can do it by specifying
java -Xms32m -Xmx128m your_application
it will be a temporary increase of heap size and if you want to increase it permanently set the following environment variable as needed.
export _JAVA_OPTIONS="-Xms64m -Xmx128m"
-Xms64m is the startup size(64MB) and -Xmx128m is the maximum size(128MB)