Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to use and have tried

sudo usermod durrantm_test -mdl durrantm_test2

but I get

Usage: usermod [options] LOGIN


sudo usermod durrantm_test -l durrantm_test2 -md durrantm_test2

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

share|improve this question
This is a great question imo. – Tim Jun 12 '12 at 17:46
up vote 3 down vote accepted
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


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.

share|improve this answer
What sort of shell are you using that allows positional parameters ($1, $2, ...) in aliases? – jw013 Nov 23 '12 at 15:43
make believe shell - apologies, I'll correct. – EightBitTony Nov 23 '12 at 20:16
Note that you may also need to rename crontabs, mailboxes, possible entries in /etc/aliases and wherever the old name might have been referenced. – Stéphane Chazelas Nov 23 '12 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. – EightBitTony Nov 24 '12 at 7:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.