AFP548 Changing the world one server at a time.

Copy folder based on group membership

Home › Forums › OS X Server and Client Discussion › Questions and Answers › Copy folder based on group membership

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #370143
    Bwilsor
    Participant

    I have to sort 1400+ user home folders into sub folders. Is there a way to do this based on the users group membership? I am trying to avoid picking them out one by one and moving them into the new nested home folder.

    #370144
    PhillyMJS
    Participant

    Assuming you’ve got Open Directory going, you’d do something like this to get a list of users in the group ‘mygroup’:

    dscl /LDAPv3/127.0.0.1 -read /Groups/mygroup GroupMembership

    You’ll get output like this:

    GroupMembership: user1 user2 user3 user4

    So you’d just need to parse that output to get the individual usernames and do an mv on each username to plunk their user folder into the correct new location.

    HTH,

    ~Philly

    #370165
    Bwilsor
    Participant

    Thanks for the ideas! I am going the parsing route o move the folders.

    #370169
    Magus255
    Participant

    You could list the directory and then pipe it though grep to filter out unwanted stuff then us awk to call mv with the proper fields.

    ls -l | grep somefilter | awk ‘{system(“mv ” $9 ” ” $4 “/”)}’

    $9 ends up being file name and $4 is the group ownership from the permissions.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.