How do I get the name of the active user via the command line in OS X?
相关问题
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- softlinks atime and mtime modification
- Avoid cmake to add the flags -search_paths_first a
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- ImportError: No module named twisted.persisted.sty
- How can I vertically align my status bar item text
- Compile and build with single command line Java (L
There are two ways-
or
getting username in MAC terminal is easy...
I generally use
whoami
in terminal...For example, in this case, I needed that to install Tomcat Server...
If you want to know who's currently logged in to the system:
(This is from a Linux system; the formatting on OS X may be slightly different, but the information should be about the same.)
There may be multiple login sessions; UNIX is designed to be a multi-user system, after all.
If you'd like to display the full name (instead of the username), add the
-F
flag:You can also retrieve it from the environment variables, but that is probably not secure, so I would go with Andrew's answer.
printenv USER
If you need to retrieve it from an app, like Node, it's easier to get it from the environment variables, such as
process.env.USER
.I'm pretty sure the terminal in OS X is just like unix, so the command would be:
I don't have a mac on me at the moment so someone correct me if I'm wrong.