What if new directory doesn't exist?

QuestionsQuestions8 SkillsProUser Account ManagementNov, 01 2025
0102

If the new directory specified with the -d flag in the usermod command does not exist, the following will occur:

  1. No Automatic Creation: The usermod command will not create the new home directory automatically. The command will succeed, but the user's home directory will be set to the specified path, which will be empty or non-existent.

  2. Potential Issues: If the new home directory does not exist, the user may encounter issues when trying to log in or access their home directory, as there will be no directory to access.

To avoid these issues, you should:

  • Create the Directory: Manually create the new home directory before running the usermod command. You can do this using:

    sudo mkdir /new/home/bob
  • Use the -m Flag: If you want to move the contents of the old home directory to the new one, use the -m flag along with -d to ensure the directory is created and the contents are moved:

    sudo usermod -d /new/home/bob -m bob

If you have more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!