I accidentally deleted my /root folder and now my shell string is different. What gives?

2

I stupidly managed to delete my /root folder on CentOS. I re-created an empty /root folder and set root privs to it, but now my shell string in PuTTY is different.

Whereas it used to say [root@servername ~]$, now it just says -bash-4.1#.

What has happened? Have I deleted anything important inside /root? How can I restore the previous string?

WackGet

Posted 2013-04-01T04:30:23.023

Reputation: 366

This is a reminder of why good, accessible backups are important. But of course, you already knew that. ;-) – depquid – 2013-04-02T21:25:14.803

Answers

7

You probably deleted a .bashrc or .bash_profile file - these are hidden by default from ls. You could create a new .bashrc in /root with something like PS1='[\u@\h \W]\$, which would give you something similar to what you lost.

If you would like to get /root set up much the same as the initial install, instead of creating an empty /root you could cp -a /etc/skel /root - this would copy over all of the default user account files, which is likely what your distro does during the initial install. These files would include a .bash_profile, etc, specific to the distro.

Iiridayn

Posted 2013-04-01T04:30:23.023

Reputation: 248

Ah awesome. Can I copy this from one of my other user accounts (which still do have the correct shell string)? Or is there something "special" about root's? – WackGet – 2013-04-01T04:35:44.610

I've noticed that it tends to be slightly different from the /home/<user>/ files, but the default configuration is pretty distribution specific. – Iiridayn – 2013-04-01T04:37:18.593

Well it certainly worked. Thanks so much. I'll accept the answer as soon as it's possible to do so. – WackGet – 2013-04-01T04:39:06.737

3

For CentOS 6 I added back 2 default files of .bashrc and .bash_profile with the following:

-bash-4.1# vim .bashrc

# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

-bash-4.1# vim .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

Now mine looks correct [root@bvdirect-db-dev ~]#

Hope this helps!

Tony-Caffe

Posted 2013-04-01T04:30:23.023

Reputation: 141