Operating System - Linux
1829173 Members
2169 Online
109986 Solutions
New Discussion

Re: chown -r me:group .* misunderstanding effects

 
SOLVED
Go to solution
Joseph P. Smith
Regular Advisor

chown -r me:group .* misunderstanding effects

The good news is that this is a development system. At login I discovered that I landed in / rather than $HOME - /usr/users/mydir. I su'd to root, and discovered that I did not own my $HOME directory and files in it and below it.

In order to correct this as root I executed

$ cd /usr/users
$ chown me:mygroup mydir
$ cd /usr/users/mydir
$ chown -R me:mygroup *

The result was all files in and below $HOME received me:mygroup ownership. Excellent!

This left the ownership of the hidden files/dirs in $HOME unchanged. In $HOME I then executed
chown -R me:mygroup .*

Lo and behold, the command traveled up a level to /usr/users and then down through ALL /usr/users, making me:mygroup the owner. My career passed in front of my eyes.

Please help me understand the chown syntax or file specification wildcard mis-understanding/ignorance I am operating under.

I have searched ITRC with no relevant references found. If there is a relevant article please provide a pointer. Thanks for your help.

Joe S.
9 REPLIES 9
Rick Garland
Honored Contributor

Re: chown -r me:group .* misunderstanding effects

I always change the . files manually because of what you just described. I had the same movie in my eyes at that time as well.

There is a way using the ? symbol but have not researched enough. the manual method may take longer but I do feel safer.

Slawomir Gora
Honored Contributor
Solution

Re: chown -r me:group .* misunderstanding effects

Hi,

this .* is not chown syntax but shell special pattern.

look at results of command:
1. echo .*
. ..
this means your command was interpreted by shell as:
chown -R me:mygroup . ..

when you want to change permisions or owner to .* files and directores you should use syntax:

chown -R me:mygroup .??*
where ? - Matches any single character.
Don't use single ? because:
echo .? -> means ..

But in your example the best/easiest solution to change owner of all files and dirs was:
cd /usr/users
chown -R me:mygroup mydir


Heiner E. Lennackers
Respected Contributor

Re: chown -r me:group .* misunderstanding effects

Hi,

if you use ".*" you also select the directory ".." which is the parent directory. The option -r will now change all right in all selected directory, even in the parent directory and all subfolders of the parent directory.

To avoid this i always use ".??*" and handle all dot-files matching ".?" manually.

HeL
if this makes any sense to you, you have a BIG problem
Joseph P. Smith
Regular Advisor

Re: chown -r me:group .* misunderstanding effects

Thank you all. Slawomir Gora gets the rabitt! Anyone know how that gets assigned?

I had better know how the shell special characters are interpreted. The suggestions of .??* and correct directory spec are very useful. Thnx again.

Joe S.
Andrew Bruce
Valued Contributor

Re: chown -r me:group .* misunderstanding effects

The best solution has already been given (chown -R the directory from the parent level).

Other pattern matching that will work:

chown -R me:mygroup .[A-z]*

will catch any file or directory beginning with . followed by any letter.

You could extend this to include numbers and other characters.

Or:

chown -R me:mygroup .[!.]*

which will match any file or directory beginning with a . and followed by any character, but *NOT* a second . (i.e. "dot-not-dot-but-anything-else")

Regards,

Andy Bruce
I Love it when a plan comes together!
Andrew Bruce
Valued Contributor

Re: chown -r me:group .* misunderstanding effects

I forgot to add:

for more information, have a look in the man page for the shell you are using (e.g. man bash) and look for the explanation of pattern matching.

Indeed, if you do a "man bash" and search for:

Pattern Matching

The second occurrence is the section you want to read up on!

Regards,

Andy Bruce

ps if you're dishing out points, don't give me double as I meant to put this bit in with my first respone! ;-)
I Love it when a plan comes together!
Michael Schulte zur Sur
Honored Contributor

Re: chown -r me:group .* misunderstanding effects

Hi,

you could have done it with
chown -R me:mygroup /usr/users/mydir
This would have included all . files as well.
chown -R .* is very dangerous as said.
I wrecked a production system twice. :-(
I was new into Unix and I tried to set the owner of the .* files.
Luckily the sysadmin did have a few open windows at all times so he could repair it.

greetings,

Michael
Joseph P. Smith
Regular Advisor

Re: chown -r me:group .* misunderstanding effects

Closing thread & thanks to all. Going to the firinq squad! ;-) [not really]
Joseph P. Smith
Regular Advisor

Re: chown -r me:group .* misunderstanding effects

As stated above.
Joe S.