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).