1

I wanted to use and have tried

sudo usermod durrantm_test -mdl durrantm_test2

but I get

Usage: usermod [options] LOGIN
...

However

sudo usermod durrantm_test -l durrantm_test2 -md durrantm_test2

doesn't give an error but seems repetitive, can I shorten it?

1
  • This is a great question imo.
    – Tim
    Commented Jun 12, 2012 at 17:46

1 Answer 1

3
usrmodx() { sudo usermod "$1" -l "$2" -md "$2"; }
usrmodx durrantm_test durrantm_test2

But shouldn't it be,

sudo usermod -l new_name -md new_dir old_name

so

sudo usermod -l durrantm_test2 -md durrantm_test2 durrantm_test

and as a function,

moveuser() { sudo usermod -l "$2" -md "$2" "$1"; }
moveuser durrantm_test durrantm_test2

or am I missing something?

This assumes you're using a shell which supports functions (e.g. bash), and avoids aliases because you can't use positional variables.

4
  • 1
    What sort of shell are you using that allows positional parameters ($1, $2, ...) in aliases?
    – jw013
    Commented Nov 23, 2012 at 15:43
  • make believe shell - apologies, I'll correct. Commented Nov 23, 2012 at 20:16
  • 1
    Note that you may also need to rename crontabs, mailboxes, possible entries in /etc/aliases and wherever the old name might have been referenced. Commented Nov 23, 2012 at 22:47
  • The original query is about a way to shorten a repetitive command, not a way to successfully and completely migrate user names. Commented Nov 24, 2012 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .