如何在 linux 或 unix 上找到用户的主目录? [英] How to find a user's home directory on linux or unix?
本文介绍了如何在 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.
推荐答案
对于类 UNIX 系统,您可能希望使用 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"}
).
这篇关于如何在 linux 或 unix 上找到用户的主目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文