Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi
I've created a plain text file that has a list of names each on a separate line all lower case and no space. I'm using:
for i in `cat /Users/home/Desktop/list.txt`; do mkdir $i; done
which creates appropriate folders based on the names in the list. How can I change the owner permission of each folder to be owner based on the name of the created folder? For example if I issue:
for i in `cat /Users/tony/Desktop/batch/list.txt`; do chown -R:Staff $i; done
The command completes with no errors but no change is made. When I try using chmod instead or in conjunction with chown I either get 'invalid argument' errors or again no change.
Imported from the Apple Support Forums via the Wayback Machine 🔗
You need a space between "-R" and "staff", which should be all lowercase.
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
for i in `cat /Users/tony/Desktop/batch/list.txt`; do chown -R:Staff $i; done
If you are not a member of the target group, you will need sudo and if you are trying to change the owner, rather than the group, you would also need to use sudo
while read newdir do mkdir -p "$newdir" sudo chown -R :staff "$newdir" done </Users/tony/Desktop/batch/list.txt
You will be prompted at least once for your password (this also assumes you are part of the admin group).
The "..." around $newdir, protects it from any spaces in the directory names.
The *while read* loop is more flexible, and does not get upset about spaces that may be in filenames.
And you have already been told about a space between the -R and the :staff
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi
Thank you both for your help. The directories get created fine but the second part is still not working. This is what I get when I run:
bash-3.2# for i in `cat /Users/tony/Desktop/batch/list.txt`; do chown -R staff $i; done chown: staff: Invalid argument chown: staff: Invalid argument chown: staff: Invalid argument
Owner permissions don't change to the names in the list
bash-3.2# ls -la /Users/tony/Desktop/batch drwxr-xr-x 2 root staff 68 29 Nov 17:37 adameve drwxr-xr-x 2 root staff 68 29 Nov 17:37 bertweedon drwxr-xr-x 2 root staff 68 29 Nov 17:37 charlierich
I'm clearly doing something wrong.
Tony
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi
Thank you for your help. I really like this script which worked beautifully without error. However the folder owner did not change.
I'm clearly doing something wrong.
Tony
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
If you are changing the group of the files why not just use the chgrp command?
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi
The group's not a problem. I want to change the owner.
Tony
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi Tony, what about
while read newdir do mkdir -p "$newdir" sudo chown -R "$newdir" "$newdir" done </Users/tony/Desktop/batch/list.txt
Cheers
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
drwxr-xr-x 2 root staff 68 29 Nov 21:42 adameve drwxr-xr-x 2 root staff 68 29 Nov 21:42 bertweedon drwxr-xr-x 2 root staff 68 29 Nov 21:42 charlierich
I would give you a Helpful but it's not listed as an option now.
Tony
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi again Tony, I suspect the problem is that they aren't in the local directory, do these accounts exist? AFAIK, OSX can't chown something to someone who doesn't exist.
Cheers
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Do you want to change the owner to 'staff' ?
if that is the case, then do not use the : before 'staff'
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Antonio Rocco wrote: The group's not a problem. I want to change the owner.
OK, Let's take a step back here. Just what kind of problem are you experiencing with these files that makes you want to change the owner?
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi
Perhaps I should explain? This is an AD-OD integrated environment. Network Profiles exist on Active Directory. Students own their own profiles. There is ample storage on the Open Directory. There is a requirement to provide shared folders that are specific to those users.
For example a student called Adam Smith has a profile on AD called adamsmith and is the owner of that profile. I can create a folder based on his name easily enough but making Adam Smith the owner as the folder is created seems to be the elusive part. The Group owner I can easily change using chmod 755 for all created folders later.
I hope that's clear enough?
Tony
0
Apple Support Community member·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Hi Andbrowny
I think this is where I'm going wrong! I've missed the obvious. I Clearly can't change directory ownership for users that don't exist.
Unless someone knows different?
I need to to test the suggestions given so far on the system I want this to apply to. Like a dummy I've been testing it locally and this perhaps why it does not work?