How to find a user's home directory on linux or unix?

anon picture anon · Jan 29, 2009 · Viewed 182.3k times · Source

How do I find the home directory of an arbitrary user from within Grails? On Linux it's often /home/user. However, on some OS's, like OpenSolaris for example, the path is /export/home/user.

Answer

Daniel Hiller picture Daniel Hiller · Jan 30, 2009

Normally you use the statement

String userHome = System.getProperty( "user.home" );

to get the home directory of the user on any platform. See the method documentation for getProperty to see what else you can get.

There may be access problems you might want to avoid by using this workaround (Using a security policy file)