Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: file ownership issue, need a suggestion

  1. #1
    Join Date
    Aug 2008
    Location
    Little Exuma, Bahamas
    Posts
    699

    Default 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?
    Last edited by caprus; 30-Apr-2011 at 19:02. Reason: fixed typo
    MS user 1988-2008, Linux user 1998-present, openSUSE user since 2004
    (The first computer I used had a punch card reader)

  2. #2
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: file ownership issue, need a suggestion

    There is no such thing as no owner. The owner is the account "nobody". Just a small nitpick.

    This will do the job for you:

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

    Substitute the user as necessary.

  3. #3

    Default Re: file ownership issue, need a suggestion

    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

  4. #4
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: file ownership issue, need a suggestion

    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)

  5. #5

    Default Re: file ownership issue, need a suggestion

    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.
    >
    > 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

  6. #6
    Join Date
    Jun 2008
    Location
    Earth - Denmark
    Posts
    10,730

    Default Re: file ownership issue, need a suggestion

    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

  7. #7
    Join Date
    Aug 2008
    Location
    Little Exuma, Bahamas
    Posts
    699

    Default Re: file ownership issue, need a suggestion - SOLVED

    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:
    Code:
    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.
    Code:
    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.
    MS user 1988-2008, Linux user 1998-present, openSUSE user since 2004
    (The first computer I used had a punch card reader)

  8. #8
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: file ownership issue, need a suggestion - SOLVED

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

  9. #9
    Join Date
    Aug 2008
    Location
    Little Exuma, Bahamas
    Posts
    699

    Default Re: file ownership issue, need a suggestion - SOLVED

    Opps, so I did.

    However
    Code:
    # find . -user nobody -print0 | xargs -0 chown greyshark:users
    chown: missing operand after `greyshark:users'
    MS user 1988-2008, Linux user 1998-present, openSUSE user since 2004
    (The first computer I used had a punch card reader)

  10. #10
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: file ownership issue, need a suggestion - SOLVED

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •