What I need is something like:
$ who-has-uid 1000
cyrus
I know the file /etc/passwd contains such informations, I'm not asking a script that parses it.
|
What I need is something like:
I know the file
| |||
|
feedback
|
|
If you have root access, it's as simple as:
| |||
|
feedback
|
|
You could try getent (getent man page):
You could parse out just the username with sed. | |||
|
feedback
|
Note that this will work (assuming Perl is configured properly) even if the information comes from somewhere other than the There's no real error checking; If you don't insist on a one-liner, you can put this somewhere in your
| |||||||||||||||
feedback
|
|
Use awk, (usually installed GNU awk, gawk) Tell it to use colon as a delimiter, see if field 3 (the UID) is 1000, then print the first field (username)
This is if the info is in /etc/passwd, if you have network login info (e.g. on NIS or LDAP) getent works better
You do need single quotes: if you use double quotes, bash will try to figure out what $1 means to the shell, and not pass it to gawk. | ||||
feedback
|
id -u cyrusjust do the opposite thing). – cYrus Nov 30 '11 at 22:28who-has-uid 100will match also100,1001, ... I would usegetent passwd 100 | cut -f1 -d:instead. – cYrus Nov 30 '11 at 22:45