Saturday, February 27, 2010

When a unix dot means a whole different world...

Subtitle: new ways to shoot yourself in the foot.

A week ago I was changing ownership on a web site subdirectory:
chown -R darren:www *

There were some files/directories that start with a dot, such as .htaccess, so I then did:
chown -R darren:www .*

If you just screamed out "Nooooo!!!!" you are allowed to polish your Unix Guru badge and wear it with pride. Personally I just sat there wondering why it was taking so long to return and why my disk was suddenly sounding so busy.

That's right. ".." refers to the parent directory. It had gone up a directory, then was using -R to recurse into every subdirectory on my web site, destroying previous ownership settings with abandon.

I realized after a few moments and killed it, but the damage was done, and I'm still discovering small parts of web sites that got broken. But a question for the gurus: how should I change all files and directories in a tree including those that start with a dot? Did I need to use some complicated find and chown combination command?


keith.s.wilkinson said...

I found O'Reilly's "Bash Cookbook" an interesting and insightful explanation of a lot of the gotchas and how to work around them...

Curt Sampson said...

No, you just needed the recursive option one level up: chown -R darren:www ..*

It's rather odd to want to change ownership or permissions on everything under a directory but not the directory itself. (You'd do that if you want current stuff to be changed, but you want someone with permissions to the dir but nothing under that to be able to remove and recreate the things under it so that they then do have permission.) However, if you really wanted to do this, you could simply change the top-level directory alone back to whatever permissions you want anyway.

* Italics, because apparently typewriter font is too dangerous to put into blog comments.

darren said...

Thanks Curt; actually ".." was exactly what I didn't want to change.

But, yes,
chown -R darren:www .

was what I wanted. I use that a lot, not sure why I didn't think of it at the time. (It is possible I had a reason to not change current directory but, as you say, that would be unusual.)