file ownership issue, need a suggestion

I have to share a fairly large folder, with dozens of subfolders and hundreds, maybe even thousands of graphics files. Unfortunately I keep finding myself unable to do so because of random files scattered within the subfolders that have no owner. (I’d love to know how that might have happened, but that’ll have to wait for another day)

Here’s the scenario. (in Dolphin) I right click on the folder, then on Properties, then on the Permissions tab. I check the “Apply changes to all subfolders and their contents”. I then go to the share tab and click on “share this folder in the local network”. So far, so good. This is the procedure that normally works fine for setting up these quicky shares need for short term use, however this time when I click OK I get an error message “Access denied to /home/username/folder/subfolder/filename”.

So, I go find the file, right click on it, then on Properties and on the Permissions tab. Under Ownership I find “User: nobody, Group: nobody”. At this point it’s no problem to change the ownership of the file. When I then retry setting up the share I get the same problem with another random file listed. If gone through this several times already.

I’ve checked and found that most of the files in these folders are fine, but there are enough with no owners that finding them all one by one by waiting for the error to show up is going to drive me nuts.

So here’s my question. Is there a simple way to locate and change the ownership of all the files in a folder and its subfolders that are presently without owner assigned?

There is no such thing as no owner. The owner is the account “nobody”. Just a small nitpick. :slight_smile:

This will do the job for you:

find . -user nobody -print0 | xargs -0 chown caprus:users

Substitute the user as necessary.

On 04/30/2011 06:06 PM, caprus wrote:
>
snip
> So here’s my question. Is there a simple way to locate and change the
> ownership of all the files in a folder and its subfolders that are
> presently without owner assigned?

You bet. Go to the command line, su to root, the cd to the topmost
folder you want to start at. Like this

su
(enter password at promtp)
cd /home/username/folder

Then do this:
chown -r USER:GROUP *
where USER and GROUP are the name of the appropriate, er, user and group
that you want assigned.

The -r flag tells the chown command to recursively trundle through the
directories. (That is, to walk down the tree).

Most of the files there probably are already set properly but this will
hit them all in one fell swoop. You should be root when doing this, in
case there are some files there that you wouldn’t otherwise have access
to. After it finishes, just type exit to leave off being root.

HTH…

…Kevin

Kevin Miller - http://www.alaska.net/~atftb
Juneau, Alaska
In a recent survey, 7 out of 10 hard drives preferred Linux
Registered Linux User No: 307357, http://counter.li.org

On 2011-05-01 04:06, caprus wrote:

> So here’s my question. Is there a simple way to locate and change the
> ownership of all the files in a folder and its subfolders that are
> presently without owner assigned?

One more method:

Code:

#!/bin/bash
CAMINO=/data/
find $CAMINO -type f -exec chmod u+r+w,g+r+w,o-r-x-w ‘{}’ ;
find $CAMINO -type d -exec chmod u+r+w+x,g+w+r+x+s,o-r-x-w ‘{}’ ;

find $CAMINO -type f -exec chown somebody:thegroup ‘{}’ ;
find $CAMINO -type d -exec chown somebody:thegroup ‘{}’ ;

I do not bother to find out if the permissions and owners are correct: I
change them anyway. Finding out is one more operation.

Notice that I use different permissions for directories.

It is not an optimal solution.

I have that script on the root of directories where I want to keep those
permissions and ownerships.

If you really want to locate wrong files, I think “find” has options for
that. It is a complex program


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

On 04/30/2011 06:36 PM, ken yap wrote:
>
> There is no such thing as no owner. The owner is the account “nobody”.
> Just a small nitpick. :slight_smile:
>
> This will do the job for you:
>
> find . -user nobody -print0 | xargs -0 chown caprus:users
>
> Substitute the user as necessary.

Nicely surgical.

My method was more brute force but will set all files to the new owner
regardless of current ownership which can be handy. but yours is a very
efficient targeted approach. I had to hit the man pages to grok the
-print0 and learn about xargs so it was a good learning opportunity too.
Now if I can just remember it if/when I need to do something like
that…

…Kevin

Kevin Miller - http://www.alaska.net/~atftb
Juneau, Alaska
In a recent survey, 7 out of 10 hard drives preferred Linux
Registered Linux User No: 307357, http://counter.li.org

On 05/01/2011 04:06 AM, caprus wrote:
>
> random files scattered within
> the subfolders that have no owner. (I’d love to know how that might
> have happened, but that’ll have to wait for another day)

does anyone have write access to those directories from any non-Linux
machine or file system?

not sure (as i know very little about either ms-windows or networking
with them) but wouldn’t it be possible files written from a files system
with no understanding of file ownership might land in a *nix system broken?

as i recall just a copy from a usb stick with a fat file system is
enough to have some vestiges of the deficient origin…


CAVEAT: http://is.gd/bpoMD
[openSUSE 11.3 + KDE4.5.5 + Thunderbird3.1.8 via NNTP]
HACK Everything → http://www.youtube.com/watch?v=j5b4CCe9pS8&NR=1

Thanx to everyone who repied so promptly. It’s this kind of experience that makes OpenSUSE so special.

@ken_yap
I’m suspect my inexperience with linux syntax shows here:

X205:/home/greyshark # cd Pictures

X205:/home/greyshark/Pictures # find -user nobody -print0|xargs -0 chown greyshark:users
chown: missing operand after `greyshark:users'
Try `chown --help' for more information.

X205:/home/greyshark/Pictures # find -user nobody -print0|xargs -0 chown greyshark:users /u
chown: cannot access `/u': No such file or directory

X205:/home/greyshark/Pictures # find -user nobody -print0|xargs -0 chown -R greyshark:users
chown: missing operand after `greyshark:users'
Try `chown --help' for more information.

X205:/home/greyshark/Pictures # find -user nobody -print0|xargs -0 chown -R greyshark:users /u
chown: cannot access `/u': No such file or directory

X205:/home/greyshark/Pictures # cd..

X205:/home/greyshark # find -user nobody -print0|xargs -0 chown -R greyshark:users /Pictures
find: `./.gvfs': Permission denied
chown: cannot access `/Pictures': No such file or directory

X205:/home/greyshark # find -user nobody -print0|xargs -0 chown -R greyshark:users /home/greyshark/Pictures
find: `./.gvfs': Permission denied

X205:/home/greyshark # find -user nobody -print0|xargs -0 chown greyshark:users /home/greyshark/Pictures
find: `./.gvfs': Permission denied

@atftb
Your approach seems to have done the job, although the command prompt returned so fast I was a little skeptical, however the problem does seem to be resolved now.

X205:/home/greyshark/Pictures # chown -r greyshark:users *
chown: invalid option -- 'r'
Try `chown --help' for more information.

X205:/home/greyshark/Pictures # chown -R greyshark:users *

@DenverD
The short version:

wouldn’t it be possible files written from a files system with no understanding of file ownership might land in a *nix system broken?

Correct, that seems to have been the cause of the problem.

The long version:

The files in question were all RAW files that were downloaded from camera (with F-Spot) and presorted in OpenSUSE (with Picasa). They’re all stored in subfolders within /Pictures. Post-processing has to be done on a proprietary program (Nikon CaptureNX2) that only runs on Windows, so I run that program on XP running in a VM, and Save As the output files directly back to the shared folder /Pictures that’s mapped to a drive letter in XP.

Everything was working fine until yesterday when I was unable to save from XP to any /Pictures subfolders. That’s when I discovered the scenario described in my original post. i.e. the permissions applied to /Pictures no longer applied to the subfolders.

I don’t know why this system worked for several months before I had any problems, and even when I did get this issue most of the files were still saved with their ownership as greyshark:users as expected, but a small percentage had nobody:nobody applied instead.

Gimp is getting better and better at post-processing my RAW files, and I look forward to the day when I can stay away from MS based software altogether and still get my work done.

Your eyes missed the . (dot) as the first argument to find. When in doubt, cut from the posting.

Opps, so I did.

However

# find . -user nobody -print0 | xargs -0 chown greyshark:users
chown: missing operand after `greyshark:users'

That means there are no more files to change in the subtree starting with . (current directory). If that error message bothers you, use xargs -0 -r chown greyshark:users. -r is equivalent to --no-run-if-empty if you look at the man page.

And of course be careful what your current directory is when you run this pipe. Any time you are root, you have the big bomb button in your hands so make sure you understand what the command will do, and double check your typing before hitting return. Otherwise you will be looking for the backups or kicking yourself metaphorically.

On 2011-05-01 11:15, DenverD wrote:
> not sure (as i know very little about either ms-windows or networking
> with them) but wouldn’t it be possible files written from a files system
> with no understanding of file ownership might land in a *nix system broken?

Well, you adjust in samba the permissions. I’m no samba expert, far from
it, but I know it is done. In any case, the kernel will put some default
permissions.

> as i recall just a copy from a usb stick with a fat file system is enough
> to have some vestiges of the deficient origin…

Yes, but again the kernel puts default permissions and ownerships, taken
from fstab and mount options.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

On 2011-05-01 16:06, ken yap wrote:
> And of course be careful what your current directory is when you run
> this pipe.

Which why I run find with full path given.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” at Telcontar)

Makes sense… thanx again.

Thanks to all who answered so quickly. It’s a real credit to the forums.opensuse.org community that this thread got so many good responses and follow-ups in such a short time.