如何在linux或unix上找到用户的主目录? [英] How to find a user's home directory on linux or unix?

查看:399
本文介绍了如何在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"}).

这篇关于如何在linux或unix上找到用户的主目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆