2

I wonder how in one command I can switch to another user (in my case it is usually root) and still remain in the same location where I am before the change.

I usually do it this way, unfortunately taking many steps:

user1@m:~/loc1/loc2$ pwd
/home/user1/loc1/loc2

user1@m:~/loc1/loc2$ su -
Password: 

root@m:~# cd /home/user1/loc1/loc2

root@m:/home/user1/loc1/loc2# 

I am looking for something like:

user1@m:~/loc1/loc2$ su - && ...

or similar, which will give me this result:

root@m:/home/user1/loc1/loc2# 
0

2 Answers 2

4

According the manual, - and -l are the same option.

-l Simulate a full login. The environment is discarded except for HOME, SHELL, PATH, TERM, and USER. HOME and SHELL are modified as above. USER is set to the target login. PATH is set to ``/bin:/usr/bin''. TERM is imported from your current environment. The invoked shell is the target login's, and su will change directory to the target login's home directory.

- (no letter) The same as -l.

By not specifying -l or -, the directory is not changed.

2

The simplest solution:

user1@m:~/loc1/loc2$ su root

or even (thanks to @Christopher):

user1@m:~/loc1/loc2$ su
0

You must log in to answer this question.

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