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.
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.
chown will work with hidden files and directories. In the following example, we will change user and group ownership for all files in ~/some/folder. All files includes all hidden files (e.g. .bashrc,.profile etc.) and folders at the ~/some/folder level and below. Note in particular that we do not wish to change ownership of ~/some, and so we will exclude the file ~/some/.. from the ownership changes.
$ cd ~/some/folder
$ sudo chown -R usrname:grpname .
$
Using for-loop with ls -A option, We can find all hidden files and directory exclude . and .. and then change the ownership for all hidden files and directory.
for i in `ls -A | grep "^\."`;do chown -R user:group $i;done
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 doingwill not do the hidden files and directories. However if you follow it with
then you will do all the hidden files, (but not
.
or..
as/home/user/.*
would do). Having said all that, I would expectto 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.i believe the following command should work for this
"chown -R" works, but an alternative would be using find.
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.You can change the
dotglob
attribute temporarily to expand . files and then revert it.More on
dotglob
can be found herechown
will work with hidden files and directories. In the following example, we will change user and group ownership for all files in~/some/folder
. All files includes all hidden files (e.g..bashrc
,.profile
etc.) and folders at the~/some/folder
level and below. Note in particular that we do not wish to change ownership of~/some
, and so we will exclude the file~/some/..
from the ownership changes.Using for-loop with
ls -A
option, We can find all hidden files and directory exclude.
and..
and then change the ownership for all hidden files and directory.Use
xargs
option withls -A
For More details Click Here and Visit my Site
To chown ALL files in current directory and subdirectories for current user;
or if user can't chown some files due to restricted permissions;
You could do something like
The
-A
(capital A) is important as it excludes '.' and '..'