(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Recursive chown



I had email this morning from someone using "chown" to fix up permissions on a directory. He had discovered "-R" in the man page but had run into a small problem.

Let's say the directory was /usr/fred. He had done:

cd /usr/fred
chown -R fred:group *
 

He noted that had done pretty much what he wanted, but had ignored the "dot" files: .profile, .login etc.

So to fix that, he did:

cd /usr/fred
chown -R fred:group .*
 

That succesfully changed the ownership of the "dot" files, but had an unexpected (to him) side effect: /usr was also changed.

Of course that would be true, because ".*" includes ".." and the ".." of /usr/fred is /usr. A useful command flag seemed to be difficult or impossible to use as desired.

Well, that's not the case. The "-R" is perfectly happy to do the job if you invoke it like this:

cd /usr/fred
chown -R fred:group .
 

See the difference? Just ".", meaning current directory. That will correctly change all fles, including .login, .profile and everything else, but it won't touch ".." and therefore leaves /usr alone.

In this case, the misuse was noticed immediately and fixed, but I have often had panic calls from people where no one can login because of making this same mistake.

Actually, there's a little more to this. How did /usr/fred get the wrong ownership to start with? I looked more closely at the email and saw that "rcp" had been used to copy files from another system. It had been correctly invoked with "-p" and "-r", so the permissions and ownership should have been preserved.

However: rcp can't create users. If, for example, "fred" doesn't yet exist as a usewr on this new system, rcp can copy Fred's files from aother system (assuming proper access) but can't magically create files owned by Fred if "fred" doesn't exist here.

So the solution is to create all necessary users before using rcp. That would have avoided all of this.



;



Technorati tags:
;


Click here to add your comments





Fri Feb 27 09:32:01 2009: Subject:   Vladimir
http://strixbg.blogspot.com
gravatar
Very helpful. Thank you!





Fri Feb 27 17:50:17 2009: Subject:   OnkarJoshi
http://onkarjoshi.wordpress.com/
gravatar
Eeeks. Someone extracted, ran Tomcat, ActiveMQ, Apache httpd as root on one of the servers I am working on inside my normal application users home folders.

Your article served as a nice quick reference for recursive chgrp/chown.

Thanks.
OJ.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar




Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Basics
       - Linux
       - Unix
       - MacOSX
       - Shell


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress