Change home directory - linux

Posted on 2011-04-21
Last Modified: 2012-05-11
I have users whose home directory is /export/home/$user. I want to change this to /home/$user. I know that the command below works

# usermod -d /home/  USER

I can issue the command and get it changed, But what if I have 200 users. Is this syntax correct

# usermod -d /home `cat /etc/passwd | cut -d":" -f1`

Question by:mnis2008
    LVL 31

    Expert Comment

    The command is wrong

    It should be
    usermod -d /home/$user $user

    Run the following script

    Users=$(cut -d: -f1 /etc/passwd)

    for User in $Users
    usermod -d /home/$User $User
    LVL 31

    Accepted Solution

    To check if the command is working as per your expectation, first do this

    Users=$(cut -d: -f1 /etc/passwd)

    for User in $Users
    echo usermod -d /home/$User $User

    This way you will be able to see the entire set of commands then remove echo
    LVL 38

    Expert Comment

    If all the home directories are defined in /etc/passwd, then
    # sed "s/\/export\/home/\/home/g" /etc/passwd > /etc/

    Once verify /etc/ ok, then
    # cp /etc/passwd /etc/passwe.backup
    # cp /etc/ /etc/passwd

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
    Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now