?
Solved

aliasing "ls" giving problems, directories not showing up in color

Posted on 2003-02-25
12
Medium Priority
?
538 Views
Last Modified: 2013-12-15
Hi everyone,

I'm having trouble trying to set up color through my PuTTY terminal.  I am working via a shared web server, which is running Red Hat 7.2, and I am editing the .bashrc file in my home directory.  Two main questions:

1) I have managed to set up an alias 'blah' that is equivalent to typing 'ls --color'.  This seems to work.  However, when I try to set up an alias for 'ls', it seems as though somehow the name 'ls' is not accepted for an alias (i.e., my text highlighting of my .bashrc file does not highlight it like the other alias names).  This same problem happens with trying to name an alias 'test'.  I'm wondering, could this be that these are reserved words or something of the like?  Okay, now here's the really weird part.  Even though 'test' is not highlighting as the other aliases do, it seems to produce the desired result when I type it at my prompt.  'ls', however, to no avail.

Here is my current .bashrc file:

# .bashrc

# User specific aliases and functions
alias www="cd www"
alias blah="ls --color"
alias test="ls --color"
alias ls="ls --color"

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

2) I can't figure out how to get my terminal (or, whatever else is the culprit) to display the prompt etc. in color (I am under the impression that there are built-in rules for this?  Or is it just something that you set manually?).  I have set my term=xterm-color and can verify this setting by typing 'echo $TERM'.  Any ideas?

Be forewarned that I am a total Linux newbie, so although I understand how to use some things, I don't have the underlying understanding of what everything means.  I've tried searching google up one side and down the other, but I don't think I'm looking for the right thing.

Thanks so much in advance for your help!

Alison
0
Comment
Question by:alisonn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +4
12 Comments
 
LVL 4

Expert Comment

by:gletiecq
ID: 8031323
I don't think you can alias ls, as it would end up being a recursive command.  "ls" would alias to "ls --color" which would alias to "ls --color --color", and so on.  How about something like:

alias lsc="ls --color"

That works in my shell.

I generally avoid aliasing anything that might likely have meaning elsewhere, as the results might be unpredictable

Greg.
0
 
LVL 2

Expert Comment

by:haydes007
ID: 8036696
yes you can alias ls. Do the following in .bashrc

alias ls='ls --color=always' <--exactly like this!
0
 
LVL 2

Expert Comment

by:linxit
ID: 8041610
Type 'alias' on its own, and you will see what aliases are set up. IIRC, ls is already aliased in Red Hat 7.2 (in fact pretty much the same as haydes007's answer.

I think it's defined in /etc/profile or /etc/bashrc (no box handy at the moment to check for sure)
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Expert Comment

by:linxit
ID: 8041713
Oops, I just noticed that you're using Putty - it only has very basic colour support, i.e. you can change the default fg/bg colours on the client side and that's about it. Multicoloured output such as ls --color just won't work.
0
 
LVL 1

Expert Comment

by:bgcboyus
ID: 8047190
See if you have a DIR_COLORS file in your etc directory
if you do modify it if not here is some code for one




# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.

# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR tty

# Below, there should be one TERM entry for each termtype that is colorizable
TERM linux
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM xterm
TERM xterm-color
TERM color-xterm
TERM vt100
TERM rxvt
TERM ansi
TERM Eterm

# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 01;34       # directory
LINK 01;36      # symbolic link
FIFO 40;33      # pipe
SOCK 01;35      # socket
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned symlinks
MISSING 01;05;37;41 # ... and the files they point to

# This is for files with execute permission:
EXEC 01;32

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.# (and any comments you want to add after a '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.tbz2 01;31
.arc 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.lha 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.bz2 01;31
.bz  01;31
.tz  01;31
.rpm 01;31
.jpg 01;35 # image formats
.jpeg 01;35
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.png 01;35
.tif 01;35
.tiff 01;35
                                                       
0
 

Author Comment

by:alisonn
ID: 8057954
Hi everyone,

Thanks for all the suggestions so far.  I think I may have discovered something that may be causing the problem.  So when I type "alias", here is the output that I get (I set up an alias "l" which does what I want, but for my own edification I'm still interested in fixing "ls"):

alias blah='ls --color'
alias dir='/bin/ls -l'
alias l='ls --color'
alias ls='/bin/ls -F'
alias pico='pico -w'
alias test='ls --color'
alias vi='vim'
alias which='type -path'
alias www='cd www'

So disregard most of the stuff, but at least I have figured out that ls is currently being aliased as something else, not from the bashrc file in my home dir.  I am on a shared server, and it looks like the alias is being set from the bashrc file in the /etc directory, which naturally, I do not have access to (since presumably it is the one that specifies for everyone on my server).  So the new problem becomes: does anyone know if there is a way that I can locally override those profiles with a lower-level file that is specific to me?

Alison

Thanks again for all the help!
0
 
LVL 2

Accepted Solution

by:
jimbb earned 300 total points
ID: 8058326
Any aliases given in the .bashrc in your home dir, or any other file that is sourced _after_ the one in /etc, will supersede the global one.

However, it's possible that the .bashrc in your home dir is not being sourced.  There is a specific order to what files bash reads, it's documented in the man page.

man bash  and specifically read the "INVOCATION" section which will explain this.
0
 

Author Comment

by:alisonn
ID: 8058348
Hi everyone,

Thanks for all the suggestions so far.  I think I may have discovered something that may be causing the problem.  So when I type "alias", here is the output that I get (I set up an alias "l" which does what I want, but for my own edification I'm still interested in fixing "ls"):

alias blah='ls --color'
alias dir='/bin/ls -l'
alias l='ls --color'
alias ls='/bin/ls -F'
alias pico='pico -w'
alias test='ls --color'
alias vi='vim'
alias which='type -path'
alias www='cd www'

So disregard most of the stuff, but at least I have figured out that ls is currently being aliased as something else, not from the bashrc file in my home dir.  I am on a shared server, and it looks like the alias is being set from the bashrc file in the /etc directory, which naturally, I do not have access to (since presumably it is the one that specifies for everyone on my server).  So the new problem becomes: does anyone know if there is a way that I can locally override those profiles with a lower-level file that is specific to me?

Alison

Thanks again for all the help!
0
 

Author Comment

by:alisonn
ID: 8058366
It is so annoying that when I try to refresh my window it ends up posting my most recent comment twice.  Why on earth does it do that?!?  :)
0
 
LVL 2

Expert Comment

by:jimbb
ID: 8058735
:)  Use the "reload this question" link in the top-left instead of your browser's Reload button.
0
 

Expert Comment

by:CleanupPing
ID: 9086176
alisonn:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 

Author Comment

by:alisonn
ID: 9101058
Thanks for the help, guys (and gals?).

What it turned out was that my .bashrc file was creating my custom ones first, and THEN was pulling all the global ones, which happened to be overwriting the ones I had just set.  So I reordered the .bashrc to get the global ones first, and then define mine, so that it would work out (since I don't have access to changing the global ones).

Here's the new .bashrc file:

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

# User specific aliases and functions
alias www="cd www"
alias blah="ls --color"
alias test="ls --color"
alias ls="ls --color=always"
alias l="ls --color"
alias vi="vim"


Thanks again!

Alison
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question