prontosystems

Q: Show all User accounts in a terminal window

Hi Community,

 

which CLI command give me a list of all Users of a system?

 

Thx & Bye Tom

Posted on Feb 16, 2013 3:09 PM

Close

Q: Show all User accounts in a terminal window

  • All replies
  • Helpful answers

  • by red_menace,Helpful

    red_menace red_menace Feb 16, 2013 3:49 PM in response to prontosystems
    Level 6 (15,546 points)
    Desktops
    Feb 16, 2013 3:49 PM in response to prontosystems

    One way would be:

    dscl . list /users



  • by BobHarris,Helpful

    BobHarris BobHarris Feb 16, 2013 4:25 PM in response to prontosystems
    Level 6 (19,633 points)
    Mac OS X
    Feb 16, 2013 4:25 PM in response to prontosystems

    As red_menace shows you can get a raw list of accounts, however many of them are for daemons or specific system file ownership but are not what you might call interactive users.  May of them may never be used as your system is not in the correct environment (such as 'nobody' which is typically assigned to a guest NFS user, assuming you were exporting a file system via NFS, which very few Mac OS X users actually do).

     

    You might try using

     

    dscl . list /users shell | grep -v false
    

     

    which will narrow down the list of users a lot.

     

    Then eliminate _uucp, as the "Unix to Unix Copy" facilities are very old and a mystery to setup (I did it once back in '87 on some PDP-11s running AT&T UNIX System V.2, but it was strange even then).

     

    You should be left with:

     

    Guest
    root
    your_short_username
    any_other_accounts_you_created_on_this_mac
    
  • by prontosystems,

    prontosystems prontosystems Feb 17, 2013 6:46 AM in response to BobHarris
    Level 1 (44 points)
    Mac OS X
    Feb 17, 2013 6:46 AM in response to BobHarris

    Hi Bob,

     

    okay thanks for your explanation. Without the filter argument I see a list of users like I would see in Linux /etc/passwd. I found a couple of arguments for the dscl command like UniqueID etc and this was what I searched. One more question: Where or in which files are this information's stored? Is there a preferences file or something like that?

     

    Thx & Bye Tom

  • by softwater,

    softwater softwater Feb 17, 2013 9:04 AM in response to prontosystems
    Level 5 (5,392 points)
    Mac OS X
    Feb 17, 2013 9:04 AM in response to prontosystems

    The simplest way to get a list of users with 'home' folders is just to type

     

    ls /Users/

     

    in Terminal.

  • by BobHarris,

    BobHarris BobHarris Feb 17, 2013 10:38 AM in response to prontosystems
    Level 6 (19,633 points)
    Mac OS X
    Feb 17, 2013 10:38 AM in response to prontosystems

    It might be /var/db/dslocal/nodes/Default/users/*, but I'm am unsure.  I did find a bunch of .plist files there that included my account name, and a bunch of the other names from the "dscl . list /Users" command.  But that could be something else too :-)

  • by prontosystems,

    prontosystems prontosystems Feb 17, 2013 11:41 AM in response to softwater
    Level 1 (44 points)
    Mac OS X
    Feb 17, 2013 11:41 AM in response to softwater

    Hi,

     

    softwater wrote:

     

    The simplest way to get a list of users with 'home' folders is just to type

     

    ls /Users/

     

    in Terminal.

     

    this isn't true because a User home directory could be restored from a Time Machine backup without existing the corresponding User on the system. In my case a user did a clean install and restored the users from the old system from a time machine backup but a login failed. With the dscl command I'm able to find out if the user really exists on the system or if only the home directory is present.

     

    Thx & Bye Tom

  • by prontosystems,

    prontosystems prontosystems Feb 17, 2013 11:49 AM in response to BobHarris
    Level 1 (44 points)
    Mac OS X
    Feb 17, 2013 11:49 AM in response to BobHarris

    Hi,

    BobHarris wrote:

     

    It might be /var/db/dslocal/nodes/Default/users/*, but I'm am unsure.  I did find a bunch of .plist files there that included my account name, and a bunch of the other names from the "dscl . list /Users" command.  But that could be something else too :-)

     

    yes I guess that this information's are stored very deep and in multiple files in the system. Nothing with keep it simple and stupid. In Linux I migrate the users from one system to another by moving the /etc/passwd, /etc/shadow and /etc/group file to the new system. It could be just that simple... ;-)

     

    Thx & Bye Tom

  • by Nicky M,

    Nicky M Nicky M May 26, 2014 12:43 AM in response to prontosystems
    Level 1 (8 points)
    Servers Enterprise
    May 26, 2014 12:43 AM in response to prontosystems

    Hi,

     

    If it can help, take a look here.

     

    http://www.easy-ict.be/page4/page41/rapidviewer-2/index.html

     

    Bye.

  • by wgrcsf,

    wgrcsf wgrcsf Mar 22, 2016 3:41 AM in response to Nicky M
    Level 1 (0 points)
    Mar 22, 2016 3:41 AM in response to Nicky M

    Hi Nicky,

     

    I tried the link but it doesn't exist anymore. I'm curious on the content of the link.

  • by MrHoffman,

    MrHoffman MrHoffman Mar 22, 2016 6:55 AM in response to prontosystems
    Level 6 (15,637 points)
    Mac OS X
    Mar 22, 2016 6:55 AM in response to prontosystems

    prontosystems wrote:

     

    Where or in which files are this information's stored? Is there a preferences file or something like that?

     

    OS X user data is stored in an LDAP database.   Either a file-based LDAP database running locally and with no networking required (the dslocal stuff), or the user data is stored LDAP servers accessed via and running on the network, or the data is stored both in parallel.

     

    If you want to rummage the data, use the dscl tool and/or the LDAP programming interfaces or related.   These tools will deal with figuring out what data is stored where, and on any particular system.   Whether that data is either stored entirely locally, or in an Open Directory or Active Directory database, or otherwise.

  • by dickguertin,

    dickguertin dickguertin Oct 6, 2016 11:31 PM in response to prontosystems
    Level 1 (8 points)
    Oct 6, 2016 11:31 PM in response to prontosystems

    I prefer to get name and associated number for both Users and Groups.  This works for me in Terminal.app:

     

    dscl . -list /groups gid   # all group names and GID

    dscl . -list /users uid      # all user names and UID.

  • by Mark Jalbert,

    Mark Jalbert Mark Jalbert Oct 7, 2016 9:07 AM in response to prontosystems
    Level 5 (4,649 points)
    Oct 7, 2016 9:07 AM in response to prontosystems

    Nothing with keep it simple and stupid. In Linux I migrate the users from one system to another by moving the /etc/passwd, /etc/shadow and /etc/group file to the new system

    It's even simpler. Nightly the dslocal and shadow directories are backed up. Restore /private/var/db/dslocal-backup.xar and /private/var/db/shadow-backup.xar from your backup. This should be done in Single User mode.