LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   No color for ls -l after being root on bash shell (https://www.linuxquestions.org/questions/slackware-14/no-color-for-ls-l-after-being-root-on-bash-shell-802231/)

cola 04-15-2010 01:31 PM

No color for ls -l after being root on bash shell
 
Code:

su
password:
ls -l

All files/folders names are in black characters.
But as normal user ls -l displays directories in blue and executable files in green.

It's konsole.

How can i edit the bash configuration for root user to display directories in blue?

MensaWater 04-15-2010 01:38 PM

Your normal user probably has an alias like:
alias ls='ls --color=tty'
As that user just type "which ls" to see.

Once you determine that you can add it to root's .bashrc or .profile.

bakdong 04-15-2010 01:40 PM

There may be a restriction on user number in /etc/profile.d/colorls.[your shell here]. (Which is where the alias is defined). It's worth having a look. I'm not sure why this is done.

cola 04-15-2010 01:43 PM

Quote:

Originally Posted by MensaWater (Post 3936698)
Your normal user probably has an alias like:
alias ls='ls --color=tty'
As that user just type "which ls" to see.

Once you determine that you can add it to root's .bashrc or .profile.

Where is the file .bashrc or .profile for root user?
There is no such files in /etc or /home/user

which ls for normal user: /usr/bin/ls
which ls for root user: /bin/ls

bgeddy 04-15-2010 01:46 PM

Quote:

How can i edit the bash configuration for root user to display directories in blue?
You don't have to - just use this :
Code:

su -
to run as root with a login shell.

MensaWater 04-15-2010 02:10 PM

Quote:

Originally Posted by cola (Post 3936703)
Where is the file .bashrc or .profile for root user?
There is no such files in /etc or /home/user

which ls for normal user: /usr/bin/ls
which ls for root user: /bin/ls

They would be in root's home directory. If you type "cd" as root it will take you to root's home directory (usually /root). Typically you wouldn't want root's home in /home because that is often a separate mount and you want to be able to access root even if other things aren't working in singlle user mode.

The files are simply text files. If you aren't familiar with them then you probably want to look for and go through a bash tutorial (there many on the internet) before you try anything. You do NOT want to make your root account unusable.

cola 04-15-2010 03:13 PM

Quote:

Originally Posted by MensaWater (Post 3936733)
They would be in root's home directory. If you type "cd" as root it will take you to root's home directory (usually /root). Typically you wouldn't want root's home in /home because that is often a separate mount and you want to be able to access root even if other things aren't working in singlle user mode.

The files are simply text files. If you aren't familiar with them then you probably want to look for and go through a bash tutorial (there many on the internet) before you try anything. You do NOT want to make your root account unusable.

No file named .bashrc or .profile in /root.
There is a file named "profile" in /etc.

cola 04-15-2010 03:16 PM

Quote:

Originally Posted by bgeddy (Post 3936709)
You don't have to - just use this :
Code:

su -
to run as root with a login shell.

That works,but is there any other way to run as root with a login shell?

bgeddy 04-15-2010 04:02 PM

Quote:

That works,but is there any other way to run as root with a login shell?
Well just logging in as root runs the login shell but the su utility is not meant to run a login shell unless the "-" argument is supplied. You could just set an alias in your /etc/profile so it was set for all users. Set it like this :
Code:

alias su="su -"
and su will run a login shell when it's ran. This may not always be what you want though so beware. It's the aliases that the login shell gives - this one being relevant :
Code:

ls='/bin/ls $LS_OPTIONS'
These are only set when /etc/profile is called by a login shell which in turn runs /etc/profile.d/coreutils-dircolors.sh which sets the aliases for dir colours.
Personally I just use "su -" when i want root's environment to be pure (as a login shell) but if you really want to shorten this the first supplied alias will do in which case running "su -" will have the opposite effect than normal running the interactive shell.

MensaWater 04-15-2010 04:31 PM

Quote:

Originally Posted by cola (Post 3936792)
No file named .bashrc or .profile in /root.
There is a file named "profile" in /etc.

Well as I said they're simple text files - you can create then with vi, emacs or other editors.

/etc/profile and /etc/bashrc affect all users whereas .profile and .bashrc in a user's home directory only affect that user. That is to say /etc/profile and /etc/bashrc do global settings (assuming you're using bash) whereas .profile and .bashrc are specific only to the single user.

When you type "su <user>" you're saying - switch user without invoking his environment. When you type "su - <user>" you are saying switch user and invoke his environment. There are various things that might be set for a specific user that might not be set for other users - for example the PATH variable used by root is often different than that for users simply because the commands root can use are broader than those end users can use.

Gew 02-13-2013 08:14 AM

Also, if you add a .bash_profile file in a user directory, any .bashrc in the same directory will be ignored.

GazL 02-13-2013 08:27 AM

Quote:

Originally Posted by Gew (Post 4890696)
Also, if you add a .bash_profile file in a user directory, any .bashrc in the same directory will be ignored.

That is not how it works. Also, please don't resurrect 3 year old threads.

Gew 02-14-2013 05:53 AM

Sorry about the resurrection. However, you sure this is not how it works? I figured, since I suddenly had problems that 'ls' did not give any colors in my user shell. The shell itself looked pretty mush like BASH though, and when I looked up the $SHELL variable it return BASH, so I was very well on the right shell. After one additional launch (by simply typing 'bash') I suddenly had colors in 'ls'. After 'exit', I -- once again -- had no colors. I could not find the logic here. I had the default .bashrc file in my home directory. Then I recalled that I had lately written a simple ~/.bash_profile with a couple of lines. I simply tried removing this file, and then re-logged. Now, colors were showing correctly. How do you explain this? Should I perhaps make a new thread for this issue? Like I said, I got it figured, and by simply adding my log on lines to the end of .bashrc (instead of .bash_profile), I have it solved. I'm just trying to find out what's popping under the hood here.

GazL 02-14-2013 06:34 AM

What you describe is exactly the opposite of the default behaviour that you will see in Slackware. Slackware sets the colour ls alias from a file in /etc/profile.d which means it won't be available to any non-login shells that you launch from the command line. I don't know which distro you're using or how its profiles are written, so I can't guess why you're seeing what you are, but I can tell you how it is supposed to work:

Depending on whether it is started as a login shell or not, bash will either run /etc/profile (~/.bash_profile, ~/.profile, etc.) or ~/.bashrc. The existence of .~/.bash_profile has no bearing on whether .bashrc will run or not. All that matters is whether the shell is a login shell or not, and bash will run one or the other depending on that alone.

What I like to do is have a ~/.bash_profile that does this:
Code:

case $- in
*i* )  # Interactive shell
      if [ -f ~/.bashrc ]; then
          source ~/.bashrc
      fi
      ;;
esac

... which will ensure that any aliases, functions or variables I define in my .bashrc also take effect in login shells (which would normally only run the profile files and ignore .bashrc)


If you want to go to the horse's mouth, have a read of the "INVOCATION" section of the bash man-page.


P.S.
$SHELL isn't a reliable way of determining what the current shell is.
Code:

gazl@ws1:~$ ksh
$ echo $SHELL
/bin/bash
$


yustin 02-15-2013 06:24 AM

read this
http://www.linuxquestions.org/questi...oblems-914640/

and

this
docs.slackware.com/howtos:cli_manual:shells?do=export_pdf

Quote:

A login shell reads startup files in the following order:

/etc/profile
~/.bash_profile
~/.bash_login
~/.profile

hope this helps


All times are GMT -5. The time now is 08:21 PM.