Thursday, April 30, 2009

UNIX: File permissions

How to modify file permissions

There are three types of permissions: Read, Write and Execute
And there are three groups you have to consider while changin permissions for a file. user, group (which user belongs to), others (Other users outside of the group)

Use command:
$ chmod 777 file.txt
777 = 7-> user, 7-> group, 7->others
Binary value of 7 is 111 = Read->1, Write->1, Execute->1
So 111 for all three groups.

755 = 7-> user, 5-> group, 5->others
Binary value 7 is 111.
Binary value of 5 is 101 = Read->1, Write->0, Execute->1
So only you have the permission to read, write and execute a file.
Other users can read or execute the file but cannot write.

Still editing this post. Will update soon.

Monday, April 13, 2009

JAVA: IOException - LocalRMIServerSocketFactory

"The server sockets created using the LocalRMIServerSocketFactory only accept connections from clients running on the host where the RMI remote objects have been exported"

If you r using ubuntu and while running jconsole you are getting this message, then you should comment 127.0.1.1 ~domain from /etc/hosts file.

$ sudo vi /etc/hosts
127.0.0.1 localhost
#127.0.1.1 ubuntu


This is Ubuntu specific bug.

For more information visit:
This link

Thursday, April 9, 2009

JAVA: illegal group reference

How:
You have a string "I like dollar symbol".
and you want to replace the string with "I like $ symbol".
Code:

String a = "I like dollar symbol"
String replacement = "$"
a = a.replaceAll("dollar", replacement);


This will throw an exception "Illegal group reference."

java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
at java.util.regex.Matcher.replaceAll(Matcher.java:813)
at java.lang.String.replaceAll(String.java:2190)


Solution:
Here the problem is "$" is a Metacharacter which should be escaped.

  • replacement = Matcher.quoteReplacement(replacement);
    a = a.replaceAll("dollar", replacement);


    About quoteReplacement method in Matcher class
    Ref. link: Click here
    Returns a literal replacement String for the specified String. This method produces a String that will work use as a literal replacement s in the appendReplacement method of the Matcher class. The String produced will match the sequence of characters in s treated as a literal sequence. Slashes ('\') and dollar signs ('$') will be given no special meaning.

  • put two backslashes before "$".

    String replacement = "\\$"