How to properly recursively chown files (including hidden dirs)
The following command works for me in Ubuntu. It changed all the files and directories ownership recusively
sudo chown -R someuser:somegroup YourDir
Related videos on Youtube
![Steven Lu](https://i.stack.imgur.com/D0CKc.jpg?s=256&g=1)
Steven Lu
Updated on September 18, 2022Comments
-
Steven Lu almost 2 years
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.
-
jimmij almost 9 yearsWhat shell are you using? In
bash
you need to setshopt -s dotglob
in order to match hidden files by*
or**
. -
Steven Lu almost 9 years@jimmij good to know, thanks (you can probably put that as an answer)
-
Peter Cordes almost 9 yearsDid you
chown -R *
, instead ofchown -R .
?
-
-
Richard over 6 yearsI tried
sudo chown -R me:me .
and when Ils -al
all my files are still owned by root. Why does this not work? -
vdegenne about 6 years@Richard did you try using an absolute path or
./
?