如何在linux或unix上找到用户的主目录?
问题描述:
如何从Grails中找到任意用户的主目录?在Linux上通常是/ home / user。但是,在某些操作系统上,例如OpenSolaris,路径为/ export / home / user。
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.
答
您可能希望使用shell执行 echo-username
系统(因此使用 Runtime.exec()
来运行 {/ bin / sh,-c,echo〜username}
)。
For UNIX-Like systems you might want to execute "echo ~username
" using the shell (so use Runtime.exec()
to run {"/bin/sh", "-c", "echo ~username"}
).