Rename home directory and keep all the data?

Usually the home directory name is the same as the system user, however in my case, and I have no idea how, but the home folder got renamed with an extra letter… I may have inadvertently done it but I cannot recall.

Question is how can I rename it back to the system admin user name like it should be, and keep all the existing data?

Looking at the manpage for usermod, this should do it:
sudo usermod --move-home --home /path/to/new/name

–home sets the home directory in /etc/passwd and --move-home creates the new directory and moves the contents of the previous home directory there. The new directory must NOT exist.

man usermod for more details.

3 Likes

Thanks, but when I try that all I get is a list of options

Usage: usermod [options] LOGIN

Options:
  -a, --append                  append the user to the supplemental GROUPS
                                mentioned by the -G option without removing
                                the user from other groups
  -b, --badname                 allow bad names
  -c, --comment COMMENT         new value of the GECOS field
  -d, --home HOME_DIR           new home directory for the user account
  -e, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -f, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -g, --gid GROUP               force use GROUP as new primary group
  -G, --groups GROUPS           new list of supplementary GROUPS
  -h, --help                    display this help message and exit
  -l, --login NEW_LOGIN         new value of the login name
  -L, --lock                    lock the user account
  -m, --move-home               move contents of the home directory to the
                                new location (use only with -d)
  -o, --non-unique              allow using duplicate (non-unique) UID
  -p, --password PASSWORD       use encrypted password for the new password
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -r, --remove                  remove the user from only the supplemental GROUPS
                                mentioned by the -G option without removing
                                the user from other groups
  -R, --root CHROOT_DIR         directory to chroot into
  -s, --shell SHELL             new login shell for the user account
  -u, --uid UID                 new UID for the user account
  -U, --unlock                  unlock the user account
  -v, --add-subuids FIRST-LAST  add range of subordinate uids
  -V, --del-subuids FIRST-LAST  remove range of subordinate uids
  -w, --add-subgids FIRST-LAST  add range of subordinate gids
  -W, --del-subgids FIRST-LAST  remove range of subordinate gids
Mod edit: Code block added, garbage removed.

What is the “system admin user”? Are we talking about “root”?

You need to specify which user.

sudo usermod --move-home --home /home/$USER $USER

usermod will try to adapt the ownership of the files and to copy the modes, ACL and extended attributes, but manual changes might be needed afterwards.

This may cause issues if anything has hardcoded the user’s directory.


Probably best to do this from another user, such as root, so replace $USER with the username.

1 Like

OOPS! I missed that bit out :roll_eyes:

1 Like

yeah sorry, root - the only time I entered the correct name for this ws at the installationm stage where the installer auto created the user name which was simply the same name but in lower case. As far as I know I have NOT modified any name since then, so how the home folder got it’s name changed with an added letter is a mystery. I am thinking I might just have to accept it and either move on or fully reinstall Linux…which would be a pita as I have spent a lot of time “tweaking” it out to suit!

Root’s home isn’t under /home. It is /root and i don’t think it went missing.

1 Like

it’s not it went missing! it was renamed with an extra letter

During installation the root user and it’s home dir are created automatically, you don’t enter the name.

You do enter the name for your user, which is a sudo user.

Please post the output from these commands:

ls /
ls /home
1 Like

I think we’re talking past each other and we should clarify the situation first.

ls /
bin                 dev   lib         mnt   root             sbin  tmp
boot                etc   lib64       opt   rootfs-pkgs.txt  srv   usr
desktopfs-pkgs.txt  home  lost+found  proc  run              sys   var

and…

denzooid  lost+found 

…it is here the extra letter is added…the root name (and the name created at install) is denzoid

The username for root is root.

That is the root user’s home directory.

That is your user’s home directory.

1 Like

yes, I know that but it is incorrect and does not match root which has a single o …the home name with the double o I did not create nor edit.

To sum up, in theory it will be

sudo usermod --move-home --home /home/denzooid_NEW_HOME denzooid

sorry, not trying to be obtuse, just trying to understand.

sorry again, no the new home needs to be denzoid , it is already denzooid and when I try that (change the last entry to denzoid) I get new home does not exist


Mod edit:- Please avoid consecutive posts. Remedied. No charge.

Your user is not root.

root is a special user that is called root.


You should probably leave this until you understand the system better, but here’s the command.

sudo usermod --move-home --home /home/denzoid denzoid

I repeat you should leave this until you understand the system better. As this should probably be run from a root shell, and you don’t understand what root is yet.

2 Likes

well then, if is now /home/denzooid_NEW_HOME
reverting to new-old will be

sudo usermod --move-home --home /home/denzooid denzooid

Make a backup of the /home/denzooid_NEW_HOME
It may be needed to rename it first. And it is very recommended to do this logined as root and NOT as denzooid.

sorry they are the same names in both…ok again, it is ALREADY denzooid - this is wrong- it needs to be changed to denzoid

ok fair, however the user name I entered at install was Denzoid…hmmmmm mebbe I did a typo then and added the extra o??

Which still leaves the question of changing it to the single o - maybe I should give up and just do a complete re-installation and just accept another three hours wasted setting it all up again.

Mod edit: Consecutive posts merged.

What’s the result of this command:

whoami