LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 04-15-2010, 12:31 PM   #1
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,035

Rep: Reputation: 65
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?
 
Old 04-15-2010, 12:38 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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.
 
Old 04-15-2010, 12:40 PM   #3
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
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.

Last edited by bakdong; 04-15-2010 at 12:42 PM.
 
Old 04-15-2010, 12:43 PM   #4
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,035

Original Poster
Rep: Reputation: 65
Quote:
Originally Posted by MensaWater View Post
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
 
Old 04-15-2010, 12:46 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
1 members found this post helpful.
Old 04-15-2010, 01:10 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by cola View Post
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.
 
Old 04-15-2010, 02:13 PM   #7
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,035

Original Poster
Rep: Reputation: 65
Quote:
Originally Posted by MensaWater View Post
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.
 
Old 04-15-2010, 02:16 PM   #8
cola
Senior Member
 
Registered: Sep 2007
Posts: 1,035

Original Poster
Rep: Reputation: 65
Quote:
Originally Posted by bgeddy View Post
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?
 
Old 04-15-2010, 03:02 PM   #9
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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.

Last edited by bgeddy; 04-15-2010 at 03:03 PM.
 
1 members found this post helpful.
Old 04-15-2010, 03:31 PM   #10
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
Originally Posted by cola View Post
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.
 
Old 02-13-2013, 07:14 AM   #11
Gew
LQ Newbie
 
Registered: Nov 2009
Location: Kingston, Jamaica.
Posts: 24

Rep: Reputation: 6
Also, if you add a .bash_profile file in a user directory, any .bashrc in the same directory will be ignored.
 
Old 02-13-2013, 07:27 AM   #12
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,873

Rep: Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982
Quote:
Originally Posted by Gew View Post
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.
 
Old 02-14-2013, 04:53 AM   #13
Gew
LQ Newbie
 
Registered: Nov 2009
Location: Kingston, Jamaica.
Posts: 24

Rep: Reputation: 6
Question

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.
 
Old 02-14-2013, 05:34 AM   #14
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,873

Rep: Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982Reputation: 4982
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
$

Last edited by GazL; 02-14-2013 at 05:36 AM.
 
Old 02-15-2013, 05:24 AM   #15
yustin
LQ Newbie
 
Registered: Dec 2012
Distribution: Slackware
Posts: 7

Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Color in bash shell zivota Linux - Newbie 6 12-06-2008 04:31 PM
Bash color shell L0CTiT3 *BSD 5 10-22-2008 10:59 AM
Root user bash shell look like "bash-2.05b#" and /root empty y2pk001 Linux - Security 6 03-22-2007 08:33 PM
how do i chage the color of a file or a directory in a bash shell Paxmaster Linux - Software 3 10-17-2004 11:21 PM
how change text (and background) color within the bash shell? Xavius Linux - Newbie 4 03-29-2004 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration