1

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'
user35042
  • 2,681
  • 12
  • 34
  • 60

2 Answers2

1

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"
tink
  • 1,035
  • 11
  • 20
  • 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
  • I agree, don't use single quotes for `su` as they often makes trouble – djdomi Jun 13 '21 at 09:54
0

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'
sega_sai
  • 185
  • 1
  • 7