9

I made a mistake. I copied a directory with many sub-directories and files using the sudo command. Consequently only root has permissions to do anything with the files.

Can I somehow duplicate the permissions to root for everyone/myself, in a recursive manner?

4
  • Do you want to grant permissions to another user, but still keep the files owned by root, or do you want to give the files new ownership as the originally intended user?
    – Don Simon
    Jul 1, 2015 at 16:56
  • @DonSimon, grant permissions, but if changing ownership will do the job, it's ok with me. Jul 1, 2015 at 17:01
  • Could you be more specific about what you did to copy the files (where from, where to, command used if any, etc)
    – Wilf
    Jul 1, 2015 at 17:46
  • @Wilf, I have a second drive, it was just partitioned. I mounted one of the partitions, and tried to paste the folder from a pen drive. It did not work. So I opened a terminal, and used sudo nautilus to copy the data. It was a mistake, I should have used gksudo. Jul 1, 2015 at 18:11

1 Answer 1

16

Copying things as root will make things become owned by root (gksudo I think is just to stop program settings etc becoming owned by root - see here) - you should be able to fix it using the following :

sudo chown -R $USER:$USER /<PATH>/<TO>/<COPIED>/<FOLDER>

It:

  • Uses chown
  • -R recursively modifies directories and files
  • $USER is replaced with your username by the shell (command line, bash etc), so it tells it to make the files' and folders' user and group IDs your user's.
  • Carries it out on the specified path - e.g./<PATH>/<TO>/<COPIED>/<FOLDER>. Do not do it on just /, /usr etc, as it probably will break the system.

For example:

$ touch file
$ sudo cp file filert
$ ls -l | grep file
-rw-rw-r--.  1 wilf wilf         0 Jul  2 09:42 file
-rw-r--r--.  1 root root         0 Jul  2 09:43 filert

The above commands. create a file called file, copy it as root to filert, then displays the file properties. When files are copied as root, the resulting file should be owned by root - this is what happened to your files. With the above example, filert can be made usable by a normal user using:

$ sudo chown $USER:$USER filert 
$ ls -l | grep file
-rw-rw-r--.  1 wilf wilf         0 Jul  2 09:42 file
-rw-r--r--.  1 wilf wilf         0 Jul  2 09:43 filert

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.