user577732
user577732

Reputation: 4046

List all possible owners and groups

Using either Java or bash how can I list all possible owners and groups.

For instance if I was to do the following command in a shell with an obviously wrong owner:

chown ljafdj ~/Desktop/test.txt

My output would be

chown: invalid user: `ljafdj'

The same would be for chgrp

So how can I get a list of valid users using bash or Java?

It's for an Android application and I need to display the possibilities to my user so they can change if needed.

Upvotes: 3

Views: 3080

Answers (2)

eboix
eboix

Reputation: 5133

Groups in Android are hardcoded and "are used to isolate processes and grant permissions." However, if you want to get the online username, you can use AccountManager.getAccounts().

Upvotes: 2

ziesemer
ziesemer

Reputation: 28687

Using the shell ("bash"):

For users:

getent passwd

For groups:

getent group

Just parse for the first field (before the colon) to get the actual names.

Upvotes: 1

Related Questions