How to Chown a directory recursively including hidden files or directories
Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?
Solution 1:
I'm pretty sure the -R
flag does work - it always has for me anyway. What won't work, and what tripped me up early in my command line usage, is using *
in a directory with hidden files/directories. So doing
$ chown -R /home/user/*
will not do the hidden files and directories. However if you follow it with
$ chown -R /home/user/.[^.]*
then you will do all the hidden files, (but not .
or ..
as /home/user/.*
would do). Having said all that, I would expect
$ chown -R /home/user
to get all the hidden files and directories inside /home/user
- though that will of course also change the permissions of the directory itself, which might not be what you intended.
Solution 2:
i believe the following command should work for this
chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
Solution 3:
"chown -R" works, but an alternative would be using find.
find /path/to/dir -exec chown USER {} \;
Solution 4:
Also, if you're like me you'll probably be running chown mostly from the current directory. I was accustomed to running it like this: chown rails.rails -R *
. Simply changing the asterisk to a dot (short for the current directory) like this: chown rails.rails -R .
brings in all hidden directories.