Find the answer to your Linux question:
Results 1 to 2 of 2
Hi everybody, I have users' home directories under /home directory. Now I want to move home directories from /home to /home/users/ For that I need to modify /etc/passwd So I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    Jul 2004
    Posts
    143

    substitution with sed


    Hi everybody,

    I have users' home directories under /home directory.
    Now I want to move home directories from /home to /home/users/
    For that I need to modify /etc/passwd

    So I need to replace /home/user1 to /home/users/user1 in /etc/passwd
    How can I do this by using sed
    Please suggest me.

    Regards,
    Mummaneni.

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    First, backup your existing /etc/passwd file in case something messes up.

    Anyway, the sed command would be:
    Code:
    sed --in-place -e 's/\/home/\/home\/users/' /etc/passwd
    The '--in-place' option modifies the file right there. The regex will replace every instance of '/home' with '/home/users'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •