7

I just copied a 2.8 Gb folder to my usr/home directory using Nautilus. It contains many folders and files but I have permission to read none of them. How can I globally set read & write & execute permissions for myself.

I have one user account & the root account on my computer. However I don't want to do everything as root.

5
  • The two answers so far (and I suspect others in the future) say to "chown -R ...". One should almost never do that without also specifying the "-h" option too. Especially if one is doing this as root for another user (which isn't the case in this question). Without the "-h", when chown encounters a symbolic link, it changes the ownership of the target of the link, which is almost never what is wanted (e.g. suppose there is a symlink to /etc/shadow). Commented Apr 20, 2019 at 0:32
  • so chown -R-h? I'm not sure of the format. Commented Oct 9, 2019 at 15:34
  • Either -R -h or -Rh will work, but not -R-h. Commented Oct 9, 2019 at 16:18
  • @RayButterworth Have you tested this? I've always observed (and just checked) that both chown implementations in Ubuntu--/bin/chown from GNU Coreutils and busybox's built-in chown--behave by default as if -R implied -h. That is, when chown -R with no other options encounters a symbolic link, it changes ownership of the symlink, not its target. The GNU documentation is ambiguous on this and even seems to suggest the behavior you describe. But I think that's a documentation bug. I think Coreutils chown treats -P (whose behavior is its default when -R is passed) as POSIX does. Commented Oct 9, 2019 at 17:57
  • @EliahKagan, this is the Ubuntu site, so in that context, I'm wrong. I do know that in other unix-type systems I have run into the problem, and have learned to use "-h" by habit. But without the "-h", even on Ubuntu, chown … *, with no "-R", will follow symlinks, which is almost never what one wants. I find that always typing chown -h out of habit is a good idea. Commented Oct 9, 2019 at 18:18

2 Answers 2

11

First change the ownership:

sudo chown -R username: <directory>

(the : after the username means in fact the user default group, so it resets the group too at the same time)

Now you do not need sudo anymore you can operate under your normal user account.

First get yourself read and write access to all content:

chmod -R u=rw,go=r <directory>

Which means Read and Write access for User (the user owning the files, so that is you), but only Read for Group and Other. The = means to set the right, whatever it is now, you can also use + and - to respectively add or remove the given permission.

You can prefer:

chmod -R ug=rw,o=r <directory>

or even:

chmod -R ug=rw,o= <directory>

And the result should be clear from the explanation above (I do not know why people absolutely continue to use octal encoding to do the same thing, it has no superior value, but anyway if needed, Read is 4, Write is 2 and eXecute is 1, and you have to add the values. So my last example would be 660)

There is only one remaining step. You need to put the eXecute right on each directory and subdirectory otherwise cd will not work.

For that you can do:

find directory -type d | xargs chmod u+x

The find command like it says will find, starting at directory every object that is of type d, d meaning directory here, and the xargs command will apply the following (chmod u+x) on all of them, and based on the previous explanations, the u+x part should be straightforward.

Also, next time, if you start the copy directly under your username, the permissions should be ok from the beginning. If not it means you may have strange permissions on the top directory where you do the copy.

8

What work for me is this:

sudo chown -R username yourfoldername
sudo chmod -R 755 yourfoldername

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .