Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
This is a great question imo. –  Tim Jun 12 '12 at 17:46
add comment

1 Answer

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

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.

share|improve this answer
1  
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
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. –  Stephane 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
add comment

Your Answer

 
discard

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.