/tmp/
Now I do a "su" and enter the root password.
This causes the terminal to switch to user "root" and - unfortunately - to a different directory
e.g. /home/root
Ok, I can do now a
cd /tmp
to get to the other directory.
but I could imagine that there is a way to tell Unix to stay automatically (!) in the
directory where the original "su" command was issued.
How can I achieve this?
Peter
That should happen _only if_ you do
su -
of
su - root
>
> Ok, I can do now a
>
> cd /tmp
>
> to get to the other directory.
>
> but I could imagine that there is a way to tell Unix to stay automatically (!) in the
> directory where the original "su" command was issued.
>
> How can I achieve this?
You should not have to do anything to achieve what you want. It is
default behavior. You may have put something in your .bashrc file or the
global one.
>
> Peter
>
--
.~. Jean-David Beyer Registered Linux User 85642.
/V\ PGP-Key: 9A2FC99A Registered Machine 241939.
/( )\ Shrewsbury, New Jersey http://counter.li.org
^^-^^ 08:10:01 up 10 days, 16:56, 3 users, load average: 4.61, 4.73, 4.84
'su' does not change directories; it will leave you in the same
directory.
'su -' will behave as a login and will change directories.
--
Chris F.A. Johnson, <http://cfajohnson.com>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
you don't say what (distro/version) you are using...but some Linux
distros (like mine, below) are born with 'su' doing what you wish
yours would do...
that is, change to the root user but retain the original user's
environment (current location in (for example) /tmp, PATH etc etc etc)
to jump to /root/home (and get _all_ of root's environment) i have to
'su -' or 'su - root'..
suggest you look in man su for your distro/version to determine how to
pick up root powers with the user's environment..
oh, and you might check your alias list to see if someone made 'su' an
alias for 'su -' etc...
--
see caveat: http://tinyurl.com/6aagco
DenverD (Linux Counter 282315) via Thunderbird 2.0.0.23 (20090817),
KDE 3.5.7 "release 72-11", openSUSE Linux 10.3, 2.6.22.19-0.4-default
#1 SMP i686 athlon
Nope. It does not. It leaves the directory alone. Now if you do
su -
then it will change directory.
> Assume I am currently logged in as user "karl" in a terminal with
> current path
>
> /tmp/
>
> Now I do a "su" and enter the root password.
>
> This causes the terminal to switch to user "root" and - unfortunately
> - to a different directory e.g. /home/root
Two remarks here:
[1] The use of "su" - as opposed to "su -", "su - root" or
"su -l root" should *not* take you out of the directory
you're in. It should normally give you superuser
privileges without changing your environment. The other
commands I've just listed do source root's environment
and would indeed normally take you to the root user's
home directory.
[2] Having the root user's home directory as "/home/root" is
non-standard on GNU/Linux and unless "/home/root" is on the
root filesystem, it will give you headaches when you're
attempting to boot up in single-user maintenance mode, i.e.
runlevel 1. When dropping to runlevel 1 from within any
other runlevel, you'd be okay, but when booting up to
runlevel 1, no other filesystems will be mounted than the
root filesystem, and with the root user's home directory
living on another filesystem, you would have no access to
the root user's environment variables.
> Ok, I can do now a
>
> cd /tmp
>
> to get to the other directory.
>
> but I could imagine that there is a way to tell Unix to stay
> automatically (!) in the directory where the original "su" command was
> issued.
Normally, issuing "su" without any parameters should do just that. If
it doesn't on your system, then perhaps you should check your aliases
to see if "su" was aliased to "su -" or "su - root".
--
*Aragorn*
(registered GNU/Linux user #223157)
By learning how to use the "man su" command. The -f option will be right in
front of you, as the "man su" page is quite short.
Really?
-f If the invoked shell is csh(1), this option prevents it from
reading the ``.cshrc'' file.