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:


Hate these ads?



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:



Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner



Views for this page
Today This Week This Month This Year  Overall
1940199,205 17,338

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

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




Unix/Linux Consultants


http://bcstechnology.net Full service Linux & UNIX systems integrator; Windows to UNIX/Linux Client-Server Specialist; Secure E-Mail & Website Hosting; Thoroughbred Software Developer; Custom Industrial Automation; Hardware & Electronics Experts; In Business Since 1985.


http://www.schewanick.com SCO Unix, Solaris, Linx (various), PHP, MySQL, Apache, uniBasic, dL4, Perl, System Administration and more....


larryi@ccamedical.com SCO OS5, Debian Linux, RedHat Linux, MySQL, Apache, AJAX development using dXport/dL4/Unibasic, Windows Connectivity, Sharing Resouces, Automation, Shell Scripting



Twitter
  • Nov 30 20:25
    I have 37,000 words of a 50,000 word project. I'd like to finish it this week..
  • Nov 30 20:05
    My wife made turkey sandwiches with stuffing and cranberry orange relish - I did not want to eat the last bite. Didn't want it to end!









Change Congress


Related Posts