In the context of the usermod command, the -m option stands for move-home.
It is almost always used in combination with the -d (directory) option. Here is the breakdown of what it does:
1. Moving the Actual Files
If you use usermod -d /home/newname user without -m, Linux simply updates the "address" in the /etc/passwd file. However, the actual folder and files stay exactly where they were.
If you use usermod -m -d /home/newname user, Linux does two things:
- Updates the path in the system configuration (
/etc/passwd). - Physically moves the contents of the current home directory to the new location.
2. Automatic Creation
If the new directory doesn't exist yet, -m will create it and ensure it has the correct permissions for that user.
Comparison Example:
-
Scenario A:
sudo usermod -d /home/wayne joker- Result: The system thinks joker's home is
/home/wayne, but if you look in/home/, the folder is still calledjoker. If joker logs in, he might get an error because his "new" home folder doesn't actually exist yet. - This is what you did in the previous step.
- Result: The system thinks joker's home is
-
Scenario B:
sudo usermod -m -d /home/wayne joker- Result: The system updates the path AND automatically renames/moves
/home/jokerto/home/wayne. Everything is synced up perfectly.
- Result: The system updates the path AND automatically renames/moves
Summary: Think of -d as changing your mailing address at the post office, and -m as the moving truck that actually carries your furniture to the new house!