0

So I created my users.... Now for each of there dir's I have to create the following structure.

Users Home Directory / Staff / Info / Personal

Then create a file in each dir called file1.txt, file2.txt, file3.txt

I tried something like mkdir create "users home directory / staff / info / personal but had no success I also cant find any help from research online. Yes I am very new to Ubuntu!

1 Answers1

1

Here's a script. Modify USER_LIST to suit your needs and delete the echo keywords when you've verified the script does what you want.

#!/bin/bash

USER_LIST="user1 user2 user3 user4"

cd /home || exit 1;
for user in $USER_LIST; do
    echo mkdir -p "$user"/{Staff,Info,Personal};
    for dir in Staff Info Personal; do
        echo touch "$user"/$dir/file{1,2,3}.txt;
    done;
done;

On the other hand, you could have modified the /etc/skel template before creating the users.

  • +1 for /etc/skel alone. But what happens if a username contains a space (or can it)? – Xen2050 Mar 19 '18 at 02:12
  • how could i modify the /etc/skel template? – Erik Hayward Mar 19 '18 at 02:38
  • @Xen2050 I've heard usernames can contain spaces in some niche cases (like if they are synced with a Windows Active Directory domain). So ideally USER_LIST should be changed to an array users. – wjandrea Mar 19 '18 at 03:42
  • @dsstorefile You should always use lowercase variable names in Bash. Uppercase variables are special, like shell variables (e.g. RANDOM) or environment variables (e.g. USER). – wjandrea Mar 19 '18 at 03:45