• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

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

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
alisonn
Asked:
alisonn
  • 4
  • 2
  • 2
  • +4
1 Solution
 
gletiecqCommented:
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
 
haydes007Commented:
yes you can alias ls. Do the following in .bashrc

alias ls='ls --color=always' <--exactly like this!
0
 
linxitCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
linxitCommented:
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
 
bgcboyusCommented:
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
 
alisonnAuthor Commented:
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
 
jimbbCommented:
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
 
alisonnAuthor Commented:
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
 
alisonnAuthor Commented:
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
 
jimbbCommented:
:)  Use the "reload this question" link in the top-left instead of your browser's Reload button.
0
 
CleanupPingCommented:
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
 
alisonnAuthor Commented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now