Recursive chown starting with the directory above current directory
Solution 1
This issue is caused because you have run:
sudo chown -R admin:admin .*
We know that .
indicates the current directory and ..
indicates the parent directory. When you run the command with .*
, it simply means that match any hidden file in the current directory (stating with .
), the current directory itself (.
), the parent directory (..
). Simply put anything after .
(*
means 0 or more characters). As a result the parent directory along with all of it child directories get chown
-ed to admin:admin
.
Look at this test:
test$ ls -al
drwxrwxr-x 4 foo foo 4096 Jun 3 07:15 .
drwxrwxr-x 4 foo foo 4096 Jun 2 18:06 ..
drwxrwxr-x 2 foo foo 4096 Jun 3 07:15 egg
drwxrwxr-x 2 foo foo 4096 Jun 3 07:12 spam
$ sudo chown -R bar:bar spam/.*
test$ ls -al
drwxrwxr-x 4 bar bar 4096 Jun 3 07:15 .
drwxrwxr-x 4 foo foo 4096 Jun 2 18:06 ..
drwxrwxr-x 2 bar bar 4096 Jun 3 07:15 egg
drwxrwxr-x 2 bar bar 4096 Jun 3 07:12 spam
To revert back you need to chown
the affected directories again.
I am not really sure what your plan was, but here are some ideas:
To
chown
any directory recursively (including hidden files):sudo chown -R foo:foo /spam/egg/
To
chown
only the files (including hidden files) inside that directory (not the directory itself):(shopt -s dotglob && sudo chown -R foo:foo egg/*)
To
chown
only the non-hidden files (without the directory itself):sudo chown -R foo:foo egg/*
Solution 2
I think it's the ".*" parameter for files; that matches everything starting with ".", including the "." and the ".." files. The ".." is the parent directory, which includes everything under it.
The best way is to back up one folder, and specify the actual folder you want to change (/home/admin).
DavidP
Updated on September 18, 2022Comments
-
DavidP almost 2 years
I couldn't log in to my "admin" account and Alt+Ctrl+F1 showed all my files were owned by my "standard" user. Odd.
So I carefully changed to
/home/admin
and did asudo chown -R admin:admin *
(and
.*
too).Great.
Then I couldn't log in as my "standard" user and it turns out that all the files in
/home/standard
were now owned by "admin".Pretty humorous. Why is this happening?
sudo chown -R standard:standard /home/standard/*
did the same thing, changed
/home/admin
as well as/home/standard
.I'm more confused than usual because I tried to upgrade to 15.04 and that pretty much wrecked my computer so I'm putting things back with 14.04, please be patient with me.
-
steeldriver about 9 yearsPerhaps one is a symbolic link to the other? what does
ls -l /home
say?
-
-
heemayl about 9 years@DavidP I am not clear what you are getting at..