Operating System - Linux
1829606 Members
1350 Online
109992 Solutions
New Discussion

Re: Changing current directory of root

 
Jagadesh
Frequent Advisor

Changing current directory of root

How can i set the current directory of root to /usr. When i say
#cd
it should go to /usr directory.

Thanks
Jagadesh
7 REPLIES 7
Stuart Browne
Honored Contributor

Re: Changing current directory of root

You want to change the home directory for the user 'root' ? You'll need to modify /etc/passwd, changing where it says '/root' (6th field, : delimited) on the line starting with 'root:x:0:0:...' to be '/usr', write, and save.

WARNING: Manually changing the 'passwd' file is a dangerous task. You should make a backup of the passwd file first, and ensure you can log in ON ANOTHER SESSION prior to closing the current session.
One long-haired git at your service...
Mark Grant
Honored Contributor

Re: Changing current directory of root

"cd" take syou to your HOME directory so you would need to change roots home directory which probably isn't a good idea particularly as you can't guarantee a /usr file system when you boot linux.

Maybe your best solution is to make an alias as in

alias "ucd=cd /usr"
Never preceed any demonstration with anything more predictive than "watch this"
Huc_1
Honored Contributor

Re: Changing current directory of root


I am not sure I understand you !
But if what you want is to change to an other directory then then yes alias could help you out.

Put this alias in one ./basbrc like ex:

alias myr="cd /usr/root"

this will then be there each time you start a new session.

You could also make this as a function like ex:

myr()
{
cd /usr/root
}

I prefer making a library of function (just a file full of functions I execute from .bashrc

But I feel one should limit the use of alias and such because it can get very messy and you soon forget how a system mormaly reacts

I once saw I user with more then 200 (alias, in is login that then complaind he could not control it !

OK but one or two if it makes life easy why not.

Hope this helps

J-P
Smile I will feel the difference
Martin P.J. Zinser
Honored Contributor

Re: Changing current directory of root

Hello Jagadesh,

if this is a serious problem for you, then you might just use the root account for too much of your daily work. Most of the time you should be able to use a normal account and there you can set your home to whatever you like without any risk to system integrity.

Greetings, Martin
Nat Guyton
Advisor

Re: Changing current directory of root

If you want to do this without changing the root home directory, you can do this on a shell-by-shell basis simply by:

HOME=/usr
export HOME

Then for that shell only, when you type "cd" you will go where you want. Cron jobs, other scripts, etc, will not be affected.
Never underestimate the bandwidth of a station wagon filled with backup tapes
Patrick Van Humbeeck
Valued Contributor

Re: Changing current directory of root

or you could add another user to the password file with UID 0, so root's home would be unchanged but this new user would have root access too and a different home dir.
Dan Copeland
Regular Advisor

Re: Changing current directory of root

This is not adviseable but you just need to edit the /etc/passwd file and change the home of root to /usr. whenever you type cd then it would be /usr