Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:51:53+00:00 2026-05-14T20:51:53+00:00

I received a request to add around 100 users to a linux box the

  • 0

I received a request to add around 100 users to a linux box the users are already in ldap so I can’t just use newusers and point it at a text file. Another admin is taking care of the ldap piece so all I have to do is create all the home directories and chown them to the correct user once he adds the users to the box. creating the directories isn’t a problem, but I’d like a more elegant script for chowning them to the correct user. what I have currently basically looks like

chown -R testuser1 testgroup1 /home/tetsuser1; chown -R testuser2 testgroup2 /home/testgroup2; chown -R testsuser3 testgroup1 /home/testuser3

bascially I took the request that the user name and group name popped it into excel added a column of “chown -R” to the front, then added a column of “/”, copied and pasted the username column after it and then added a column of “;” and dragged it down to the second to last row. Popped it into notepad ran some quick find and replaces and in less than a minute I have a completed request and a sad empty feeling. I know this was a really ghetto method and I’m trying to get away from using excel to avoid learning new scripting techniques so here’s my real question.

tl;dr I made 100 home directories and chowned them to the correct users, but it was ugly. Actual question below.

You have a file named idlist that looks like this (only with say 1000 users and real usernames and groups)

testuser1 testgroup1
testuser2 testgroup2
testuser3 testgroup1

write a script that creates home directories for all the users and chowns the created directories to the correct user and group. To make the directories I used the following(feel free to flame/correct me on this as well. )

var= ‘cut -f1 -d” ” idlist’ (I used backticks not apostrophes around the cut command)
mkdir $var

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:51:54+00:00Added an answer on May 14, 2026 at 8:51 pm
    awk '{ system("mkdir " $1); system("chown " $1 ":" $2 " " $1); }' idlist
    

    Tested just now for functionality. Needs to be run under root privileges of course. This doesn’t assemble commands for you to be executed under backticks or $(). It executes them directly.

    Edited to add:

    You probably want to set that one-liner up in a script file or as an alias if this is something you do often. I do suggest, however, that you learn awk. It’s a very nice little language and is actually guaranteed to be on any Posix-compliant system. (I think it’s the only one other than sh, in fact.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.