Changed ownership of all files and folder in home to 'root' by mistake

I ran chown -R root:root * by mistake in my home folder when I had root privilege (actually I was supposed to do that in other folder :-/) How do I revert back?

This is not duplicate of what it is showing up. I don't have any problem with .gvfs; folders that were affected were Desktop, Documents, Downloads, Music, Pictures, and Videos. By default, shell globbing * does not include hidden files.


Solution 1:

Run this command:

sudo chown -R ${USER}:$(id -g -n $USER) ~/*
  • sudo: Run the following command as root.
  • chown: Change the owner of a file/folder

    • -R: Recursive (apply that owner to a folder and its content)
    • ${USER}:$(id -gn)

      • ${USER}: A variable that contains your username by default.
      • :: This splits the username from the group.
      • $(id -gn) This returns the group, however it should be same as user.
        • $(): This is a command substitution, all the code in the inner of these tags will be executed, and then this will act as a variable that contains the output of these commands.
        • id: Prints user and group information for the specified USERNAME, or (when USERNAME omitted) for the current user.
        • -gn: (abbreviation of -g -n)
        • -g: Print only the effective group ID.
        • -n: Print the group name instead of the group ID.
    • ~/*: Do all these things on all the contents of the home folder.