3

I'm running an Ubuntu LTSP setup at a school with about 60 unique users. Occasionally, we need to share a document, create a directory or place a config file in every user's account. Obviously, it's not efficient to do this one at a time.

I know I can place a file in every user's home directory with:

ls /home/ | xargs -n 1 sudo cp -i <file>

But what if I need to put it somewhere specific, such as ~/.config/autostart?

Or what if I need to create the directory ~/Desktop/foo/ for every user?

Thanks for your help, and if anyone can suggest resources for me to learn more that would be awesome.

muru
  • 207,228

1 Answers1

5

cp has an option to specify the target directory separately: -t. So you can do:

for u in /home/*
do
    sudo cp -t "$u/.config/autostart" -i <file>
    sudo mkdir "$u/Desktop/foo"
done

In general, there's no simple way to manage user's home directories. You can specify what gets created in it when the home directory is first created, but after that, it's each user for itself.

Then, you'd have to use some form of scripting. In this case, I have used shell scripting. Check out the TLDP guides on Bash and scripting in Bash. Even with tools like Puppet, this is not a trivial task.

muru
  • 207,228