LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bashrc and root (https://www.linuxquestions.org/questions/linux-newbie-8/bashrc-and-root-733294/)

fluxism 06-16-2009 05:09 AM

bashrc and root
 
I have a simple couple of alias` set up on my user account.

alias ls='ls -l --color'
alias .='cd ..'
alias ..='cd ../..'

All well and good!

When I su to root, and ls, I get the normal output shown, and not my desired output long-form with colour.

So I should change the roots .bashrc too right? I tried this too my changing /root/.bashrc and the alias` aren't used.

So which file should I be editing to enable my alias commands for root? I could change the /etc/bashrc file(!?) and it would be changed system wide, but this isnt exactly what I am trying to do!

Any ideas?

jamescondron 06-16-2009 05:10 AM

/root/.bashrc

fluxism 06-16-2009 05:20 AM

Quote:

Originally Posted by jamescondron (Post 3575660)
/root/.bashrc

Indeed, this is what I would of thought too! But is not adding my alias to the ls command, here's my current /root/.bashrc file

Code:

# .bashrc

# User specific aliases and functions

alias ls='ls -l --color'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

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

I'm running CentOS by the way. ls will just give me the normal output, not the desired one.

linuxlover.chaitanya 06-16-2009 05:24 AM

Changes should appear but you will need to log out and login back for changes to take effect.

jamescondron 06-16-2009 05:25 AM

Well that section in mine looks like:
Code:

if [ -x /usr/bin/dircolors ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

(Thats /root/.bashrc)

fluxism 06-16-2009 05:36 AM

Yep, I tried logging out of root, then back in, and even tried rebooting (windows behavior! ahem). Still no joy though, editing the /root/.bashrc file doesn't add the colour and long form I am after.

noctilucent 06-16-2009 05:42 AM

Code:

su -

PMP 06-16-2009 06:10 AM

Yes You have to do su - as to make this bashrc execute while logging

fluxism 06-16-2009 06:33 AM

Ahh a pesky little -

Thank you all for the help!

:)

onebuck 06-16-2009 09:11 AM

Hi,

I like to setup properly with a '.bash_profile' and a '.bashrc'.

Quote:

~# cat .bash_profile
# .bash_profile
#08-30-06 12:21

# Source .bashrc
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi


Quote:

~# cat .bashrc
#.bashrc
#08-30-06 12:20

# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40 gws

if [ `id -un` = root ]; then
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
fi
#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
# trap 0 rm -f ~$LOGNAME/.bash_history

Yes, once you create the 'bash' files you will have to log out for that user and log back in to have the effects. I would suggest that you add your alias to the above or something along those lines :). My reasoning is that you should have good entry and exit for the 'BASH'. Things will be cleaner!

I like to have a colored prompt to differentiate the root from a normal user since I will be using multiple consoles.


All times are GMT -5. The time now is 02:04 AM.