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:
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:
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 user 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.
If you found something useful today, please consider a small donation.
Got something to add? Send me email.
More Articles by Anthony Lawrence © 2014-02-07 Anthony Lawrence