Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Seems like chown with the recursive flag will not work on hidden directories or files. Is there any simple workaround for that?

share|improve this question

5 Answers 5

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.

share|improve this answer
2  
Doing a chown on the directory has the side effect that you change the permissions on the directory itself as well as all of its contents, which may or may not be what you want. –  wfaulk May 10 '12 at 22:44

"chown -R" works, but an alternative would be using find.

 find /path/to/dir -exec chown USER {} \;
share|improve this answer
3  
note that with GNU find, using + instead of ; as the terminator to the -exec will be more efficient as it will use the minimum needed number of forks to chown instead of one fork per file/directory –  stew May 14 '12 at 2:31

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.

share|improve this answer
2  
With the side effect that you change the permissions on the current directory as well as all of its contents, which may or may not be what you want. –  wfaulk May 10 '12 at 22:39

i believe the following command should work for this

chown -hR userid:usergroup /nameofdirectory/nameofsubdir/
share|improve this answer

You could do something like

for i in `ls -A`;do chown -R user:group $i;done

The -A (capital A) is important as it excludes '.' and '..'

share|improve this answer
    
This will change only files and subdirectories in the current directory, not any lower levels. (Which may be what the OP wants.) It will also break on filenames and directory names with spaces (or tabs) in them. –  wfaulk May 10 '12 at 22:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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