Where's .bashrc for root?

31

10

I know it's not best practice, but on my dev system I login as root. What's the equivalent of the .bashrc file so I can alias some functions?

I've found the /etc/bash.bashrc & /etc/bash.bashrc.local but I'm not sure where to plop my commands.

Running x86_64 SUSE.

thanks, mjb.

mbb

Posted 2011-04-08T19:22:02.603

Reputation: 2 206

Answers

20

Probably best to put them in ~/.bashrc . It seems root doesn't get the normal ones by default in some distros, but you just cp /etc/skel/.bash* ~ to fix that.

Keith

Posted 2011-04-08T19:22:02.603

Reputation: 7 263

There we go --- I didn't know about the skel directory. Do you happen to know if that's the default? If I edit it, will it work universally if the user doesn't have a ~/.bashrc ? – mbb – 2011-04-10T19:30:35.610

1@mjb That's where new accounts get their default home directory. The useradd tool copies files from there. It is otherwise not used. You can add and alter stuff in there if you want every newly created user to have a different set of files. Think of it as the new user home dir template. – Keith – 2011-04-11T03:57:31.927

19

How about the home dir of root that is /root/?

From some aspects, root is just another user (just better, and allowed more). root has a home dir, but it is not like the other users in /home/, but simply /root/ so root:s .bashrc is therefore /root/.bashrc

The ones in /etc is system specific settings for all users, including root.


Thanks to grawity to point out that you can use ~root points to the root home dir, regardless of where it is.

You can test that with

$> echo  ~root
/root

So even thou /root will work on 99% on the systems out there ~root is probably more portable and will probably work on 100%.

~root/.bashrc

Johan

Posted 2011-04-08T19:22:02.603

Reputation: 4 827

probably work on 100%, i almots completely understand – Mateus Viccari – 2017-05-24T22:34:14.563

1Sometimes it is in /home. It's best to use ~root/.bashrc to refer to the file in root's homedir. – user1686 – 2011-04-08T19:39:06.257

5The root home directory isn't in /home because in some *nix systems, /home is on a separate partition from the system drive and is not necessarily mounted. – CarlF – 2011-04-08T19:40:43.120

You highlight why I was so confused --- there is no /root/.bashrc on this build. – mbb – 2011-04-10T19:29:49.073

2

Instead of using /root/.bashrc try using /root/.profile — it's the same thing, just a different name.

Also, if you are using su to get into root it may not be reading the .bashrc or .profile – just issuing su will not run the login scripts. try doing

su -

Jerome3k

Posted 2011-04-08T19:22:02.603

Reputation: 45

Works for ttylinux ver 14.1 [boomslang] , Linux kernel: 2.6.38.1 – GeoMint – 2018-04-03T12:51:21.993

@Slhck if they aren't the same thing, can you explain the differences? I'm a noob – Gabriel Fair – 2018-04-20T17:35:12.497

7I beg to differ that a profile and bashrc are "the same thing". – slhck – 2012-06-27T07:39:35.383

1

The similar topic: Why suse doesn't have .bash_profile or .bashrc for root user

SuSe use /etc/bash.bashrc file to manage the environment. It's not indicated to add configs on this file, becouse when the server get updated, you'll lost your personal configuration.

You can create an archieve named bash.bashrc.local on /etc. The system will load any instruction found on this file, and then search for the default conf and execute both.

# vi /etc/bash.bashrc.local

Have fun!

Leonardo Benevides

Posted 2011-04-08T19:22:02.603

Reputation: 17

/etc/bash.bashrc for SuSE Linux

PLEASE DO NOT CHANGE /etc/bash.bashrc There are chances that your changes will be lost during system upgrades. Instead use /etc/bash.bashrc.local for bash or /etc/ksh.kshrc.local for ksh or /etc/zsh.zshrc.local for the zsh or /etc/ash.ashrc.local for the plain ash bourne shell for your local settings, favourite global aliases, VISUAL and EDITOR variables, etc ... – Leonardo Benevides – 2015-11-19T13:35:39.080

0

I looked here because on my (64-bit) Slackware 14.2, logging into root does most certainly NOT source /root/.bashrc. It DOES source /home/user/.bashrc on loggin to user account. There is no /etc/bash.bashrc, or any other bash files in /etc. Nor is there any such directory as /etc/skel apparently, in slack.

jrc

Posted 2011-04-08T19:22:02.603

Reputation: 1

It's always nice to see some links to documentation. – davidbaumann – 2018-11-19T15:04:14.483

0

TL/DR: /etc/bashrc

This file get's incorporated into your ~/.bashrc as well as that of all other users including root.

Marc

Posted 2011-04-08T19:22:02.603

Reputation: 226

0

Normally the .bashrc file for the root user should be there: /root/.bashrc
If it is not the case, you can copy the 2 following files into /root, then you can edit the .bashrc file as you want.

cp /etc/skel/.bash_profile /root
cp /etc/skel/.bashrc /root

Nicolas

Posted 2011-04-08T19:22:02.603

Reputation: 815