LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-11-2005, 04:32 PM   #1
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Questions about su, su -, shells and terminal colours


Firstly, I appreciate my title doesn't make a lot of sense (and yes, I've spelt colours correctly )! Now, I have seen in various threads around LQ, people telling others to change to root with "su -". From the man page for su (albeit not the one on my system, I had to look it up online :/) I've found that the - is for a login shell. My first question is, why would one use this instead of simply "su"?

Seeing as it's a login shell, I get a quote from fortune when I log in with "su -". Is there any way to make it so that when I open a terminal window, instead of seeing just my "nick@nick:~$" prompt, I see a quote from fortune as well? I'm sure I've seen this in screenshots, but I can't remember where . I use Xfce and the command used to open a terminal is "xfterm4".

When I issue "ls" in a terminal, directories appear in blue and executable files in green. I did this by editing (or creating) a .bashrc and copying a line I found in a sample .bashrc on the web:

alias ls='ls -hF --color'.

If I now issue "ls" after logging in with "su -", in addition to the colouring above, I have .wmv, .jpg files coloured in magenta and archives like .tar.gz and .zip in red. How do I get that extra colourin g in a "normal" shell?

Hopefully this makes some sort of sense and any help is appreciated!
 
Old 08-11-2005, 05:07 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
When issuing su -, you create a login shell (as you mentioned). When you start a login shell your startup files are read. That means (if your shell is bash) /etc/profile, ~/.bash_profile, and ~/.bashrc are read in. That's important because, typically, root has different paths, different aliases, and different settings in general than normal users. It's the path change that usually gives people problems. If you just issue su without the dash, then you're not likely to have any of the sbin directories in your path. There would be a "command not found" error for utilities such as fdisk, shutdown, etc.

As for your fortune problem, you'll need to read the documentation for xfterm. It likely has a number of command line options that you can use to run fortune when you start, or a configuration file that would accomplish the same thing. I've never used it before, so I'm afraid I can't help much beyond that.

For the file colors on ls, again, that's a configuration thing. There are (at least) two files that control that behavior: /etc/dir_colors and ~/.dir_colors. Well, that's off the top of my head, they may be slightly different and/or in slightly different location. Anyway, the point is, the configuration file in your home directory will override the one located in /etc. If there is no personal configuration, the file in /etc is used. If there are no configuration at all, then ls may use a default color scheme, or maybe no colors at all.
 
Old 08-11-2005, 05:09 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Re: Questions about su, su -, shells and terminal colours

Quote:
Originally posted by Nylex
Firstly, I appreciate my title doesn't make a lot of sense (and yes, I've spelt colours correctly ;))! Now, I have seen in various threads around LQ, people telling others to change to root with "su -". From the man page for su (albeit not the one on my system, I had to look it up online :/) I've found that the - is for a login shell. My first question is, why would one use this instead of simply "su"?
So you get roots environment and not the current users.

Important for things that live in */sbin directories, for instance,
which a normal user commonly won't have in his path but
root may want to be able to use.


Quote:
Originally posted by Nylex
Seeing as it's a login shell, I get a quote from fortune when I log in with "su -". Is there any way to make it so that when I open a terminal window, instead of seeing just my "nick@nick:~$" prompt, I see a quote from fortune as well? I'm sure I've seen this in screenshots, but I can't remember where :(. I use Xfce and the command used to open a terminal is "xfterm4".
The fastest would be to source /etc/profile from
~/.bashrc


Quote:
Originally posted by Nylex
When I issue "ls" in a terminal, directories appear in blue and executable files in green. I did this by editing (or creating) a .bashrc and copying a line I found in a sample .bashrc on the web:

alias ls='ls -hF --color'.

If I now issue "ls" after logging in with "su -", in addition to the colouring above, I have .wmv, .jpg files coloured in magenta and archives like .tar.gz and .zip in red. How do I get that extra colourin g in a "normal" shell?
I don't understand that question. If you have colouring going,
all colours will be there. Just go into a directory that has those
files ...

All your alias does is to a) [-h] make file-sizes with extensions,
b) [-F] append a special character for certain and c) [--color]
turn colours on. There's no statement in there that influences
what gets which colour.


Cheers,
Tink
 
Old 08-13-2005, 02:29 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Original Poster
Rep: Reputation: Disabled
Thanks for the replies, I think I sort of understand . Would you also use "su -" if root used a different shell, or is that not possible?

It seems that the documentation for Xfce is pretty sucky, to be honest . Tink, what do you mean by "source /etc/profile from ~/.bashrc"? Also is it normal on Slackware (if anyone knows) for the .bashrc file to not be there when you install? I had to create mine.

Here is a screenshot of what I mean about the colouring. Both terminals show my home folder, the one on the left is the "normal" one and the other is from doing "su -". I get the same output if I do "su - nick" and then issue "ls".
 
Old 08-13-2005, 03:59 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,000
Blog Entries: 11

Rep: Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893Reputation: 893
Quote:
Originally posted by Nylex
Thanks for the replies, I think I sort of understand :).
Would you also use "su -" if root used a different shell,
or is that not possible?
Sure, no problem.

Quote:
Originally posted by Nylex
It seems that the documentation for Xfce is pretty sucky,
to be honest :(. Tink, what do you mean by "source /etc/profile
from ~/.bashrc"?
in ~/.bashrc
. /etc/profile


Quote:
Originally posted by Nylex
Also is it normal on Slackware (if anyone knows)
for the .bashrc file to not be there when you install? I had to create mine.
That's normal. Slack *IS* minimalistic.

Quote:
Originally posted by Nylex
Here is a screenshot of what I mean
about the colouring. Both terminals show my home folder,
the one on the left is the "normal" one and the other is from
doing "su -". I get the same output if I do "su - nick" and
then issue "ls".
That's odd...
/etc/profile fires up dircolors, which in turn gets
the definitions for colourisation from /etc/DIR_COLORS.

Unless you have an ~/.dir_colors that differs from /etc/DIR_COLORS
I can't explain how those different schemes come about.


Cheers,
Tink
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Editing /etc/DIR_COLORS does not change colours in terminal ethics Linux - General 6 02-27-2014 02:56 AM
Questions about displays, shells, and a little more Rivitir Slackware 4 11-07-2005 06:50 PM
What do the colours mean in the terminal? alaskazimm Mandriva 2 07-04-2004 08:34 AM
No .bashrc, I need colours in the terminal!! akudewan Slackware 9 06-07-2004 05:16 PM
How do I get colours in terminal (aterm)? mr-tiddles Linux - General 5 10-23-2003 11:23 AM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration