This conundrum is caused by running git pull from root.

There are various reasons for me to do so... I want my device to update code when booting up, and rc.local is run by root.

It all works mostly fine (npm install tends to fail when run by root, but that's a whole 'nother topic), the problem arises when I try to use the git repository with a non-root user afterward... some of the git files have been written by root, so now I can't use it anymore (permission denied).

So I'd like to recursively chown it back but there doesn't seem to be anything that really works on all of the little git files. I tried the -R flag and ./**/* path.

My guess is that neither of those techniques descend into dot-directories.

  • 1
    What shell are you using? In bash you need to set shopt -s dotglob in order to match hidden files by * or **.
    – jimmij
    Aug 10, 2015 at 5:56
  • 1
    @jimmij good to know, thanks (you can probably put that as an answer)
    – Steven Lu
    Aug 10, 2015 at 6:00
  • Did you chown -R *, instead of chown -R .? Aug 11, 2015 at 21:09

2 Answers 2


The following command works for me in Ubuntu. It changed all the files and directories ownership recusively

sudo chown -R someuser:somegroup YourDir
  • I tried sudo chown -R me:me . and when I ls -al all my files are still owned by root. Why does this not work?
    – Richard
    Jan 25, 2018 at 13:31
  • @Richard did you try using an absolute path or ./ ?
    – vdegenne
    May 6, 2018 at 19:01

I use tree instead:

 sudo tree -fai ~/.blabla  | xargs -L1 -I{} sudo chown youruser:youruser {}

Also take care to not run recursive chown or chmod on '/' directory or other system directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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