51

I would like to change the owner of a directory and all files and directories below it to the user nobody.

I have a /parent_dir with owner root. I want to change the owner to nobody (system user) recursively.

6 Answers 6

61

Like this:

sudo chown -R nobody /parent_dir
1
  • This requires sudo, the answer below is better. Apr 2, 2020 at 2:26
14

You may change the owner of the directory recursively using the following command. -R stands for recursive.

chown -R ownername foldername

You can also change the owner and group of the directory recursively using the following command.

chown -R ownername:groupname foldername

For more details refer this.

4

You can do this by chown with -R option. -R is for recursive.

If Demo is the folder name and apache is the user and group, then run,

sudo chown -R apache:apache Demo

This will change the owner and group of every folder and files to apache.

2

By using the -R command line parameter of chown.

chown -R nobody /parent_dir
1

Just as an alternative to the other answers:

sudo find /parent_dir -exec chown nobody {} \;

if you only want to change files you could use -type f or -type d for directories. comes in handy, when you want to chmod stuff.

1
  • another thing you can do here is restrict it to only change files from one particular owner to another. If only a few files are root owned that can save a lot of metadata writes. Jul 25, 2012 at 11:57
0

you need to make this parameter no_root_squash on /etc/exports

  • vi /etc/exports
  • no_root_squash
  • wq

Good luck.

You must log in to answer this question.