Ubuntu – chown -R user:user .* changes permissions backwards: is this the correct behaviour

chownfilesystemhidden-filespermissions

I got into a lot of trouble when changing the permission of a folder myfolder residing in /.
I issued the command

sudo chown -R luca:luca /myfolder/.*

My intention was to change ownership of all the hidden files in /myfolder.

Unfortunately I realized that also the ownership of / was changed, which of course left me with a broken system. I think this happened because .. matches .*, but still seems weird to me.

Is changing the parent directory the correct behaviour or should I file a bug report?

If it was my mistake in using chown, what are the best practices to use to prevent changing the ownership of system folders and files?

Best Answer

Remember that the command line is expanded (interpreted) by the shell before being executed

sudo chown -R luca:luca /myfolder/.*

is interpreted first as :

sudo chown -R luca:luca /myfolder/.  /myfolder/.. /myfolder/.adobe  /myfolder/.bash_history

note the /myfolder/.. in your command line

chown -R luca:luca /myfolder/.. is equivalent to chown -R luca:luca /
that makes the chown running "backwards"

Use echo /myfolder/.* when you use "*" to verify .