Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to run a command as another user in Linux. Here is what I run:

su user1 -c '/bin/mkdir /tmp/zz'

However, this gives me this error:

fatal: unrecognized command '/bin/mkdir /tmp/zz'
share|improve this question
    
su user1 -c '/bin/mkdir /tmp/zz' works for me (using Ubuntu Precise). What is the shell of user1? –  Mark Wagner Apr 9 '13 at 23:54

2 Answers 2

As suggested by Mark Wagner, I encountered the same problem when the user had a non-standard shell (in my case it was git-shell). And the solution was to do:

su -s /bin/bash -c 'some command'
share|improve this answer

You need to swap the single quotes for double quotes. Not that these are only required with commands that take parameters, or if you chain several commands together.

su user1 -c "/bin/mkdir /tmp/zz"
share|improve this answer
    
Now that's cute. The guy who downvoted me culled his own response, but didn't change his mind on my answer. :( –  tink Apr 22 '13 at 23:49

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.