Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

chown -R user.group .*

4 views
Skip to first unread message

Carbon

unread,
Nov 22, 2008, 11:09:34 PM11/22/08
to
I got a call from a user who couldn't start the GUI on a RHEL box. It
turned out that most of the files in her home directory were owned by
another user. I did a sudo chown -R user.group * in her home directory
but the hidden files and directories were still wrong. So I did this:

sudo chown -R user.group .*

I hit ^C because it was taking too long. And then I realized: .* also
matches .., the parent directory. So the chown process dutifully moved
up to /home and whacked the ownership and permissions of nearly every
other user on the system. I fixed it pretty quickly from looking at
/etc/{passwd,group} and resetting everything from /home.

I've used UNIX and Linux for 15 years, and amazingly this is the first
time I've run into this particular gotcha.

Carbon

unread,
Nov 22, 2008, 11:09:34 PM11/22/08
to

Sven Mascheck

unread,
Nov 23, 2008, 1:34:27 PM11/23/08
to
Carbon wrote:

> sudo chown -R user.group .*

> I hit ^C because it was taking too long. And then I realized: .* also
> matches .., the parent directory.

PS: One of the inherent advantages of find(1): ../ is always skipped.

WANG Cong

unread,
Nov 24, 2008, 1:27:55 PM11/24/08
to
Carbon wrote:

Aha, thanks for sharing your experience.

I think you can use:

chown -R user.group .[!.]*

Stephane CHAZELAS

unread,
Nov 24, 2008, 2:29:27 PM11/24/08
to
2008-11-23, 04:09(+00), Carbon:

Yes, that's one of the shells missfeatures that zsh has fixed.
In zsh, the globbing never expands to "." or "..". Even (.|..)
doesn't expand.

In other shells, you have to write it something like:

sudo chown -R user.group .[!.]* ..?*

--
Stéphane

Stephane CHAZELAS

unread,
Nov 24, 2008, 2:36:25 PM11/24/08
to
2008-11-24, 18:27(+00), WANG Cong:
[...]

> I think you can use:
>
> chown -R user.group .[!.]*
[...]

That ommits files named like "..foo", "..."...

Also, it's not been pointed out, but some chown implementations
do follow symlinks (if not those found while traversing the
directories, at least those passed as argument), so if ".foo" is
a symlink to "/", you'll be changing the ownership of every
file. So best is to add the "-P" option.

Another good reason to avoid the recursive options of those
commands and rely on find (or your shell if it supports it) to
do the recursion.

--
Stéphane

Carbon

unread,
Nov 26, 2008, 12:36:01 AM11/26/08
to

Thank you. I'll remember that.

0 new messages