View previous topic :: View next topic |
Author |
Message |
dj_farid l33t
Joined: 14 Jun 2004 Posts: 613
|
Posted: Mon Aug 16, 2004 1:57 pm Post subject: List files in different colors ? |
|
|
I have been making a nice .bash_profile. There are a few lines that looks like this: "cat filename". Is there a way to make the text from the files in different colors?
For example:
cat file1 <-is green
cat file2 <-is red
Thanks. |
|
Back to top |
|
|
bokkepoot Tux's lil' helper
Joined: 14 Mar 2003 Posts: 123 Location: The Hague, The Netherlands
|
Posted: Mon Aug 16, 2004 2:29 pm Post subject: |
|
|
Just to clarify: You want the output of cat to be coloured depending on the filetype ? |
|
Back to top |
|
|
dj_farid l33t
Joined: 14 Jun 2004 Posts: 613
|
Posted: Mon Aug 16, 2004 2:59 pm Post subject: |
|
|
No, It's like a one time action. I want to know if there is a command that lists a file in a specific color.
Quote: | $ cat .bash_profile
# /etc/skel/.bash_profile:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/skel/.bash_profile,v 1.10 200
2/11/18 19:39:22 azarah Exp $
#This file is sourced by bash when you log in interactively.
[ -f ~/.bashrc ] && . ~/.bashrc
echo
echo "-------------------------------------------------------------------------"
df -h | grep -v 'none'
echo "-------------------------------------------------------------------------"
cat /tmp/updates.txt | grep "ebuild"
echo
date
|
I want the output of /tmp/updates.txt to be in something else than white.
I hope this explanation explains what I am after |
|
Back to top |
|
|
tomchuk Guru
Joined: 23 Mar 2003 Posts: 317 Location: Brooklyn, NY
|
Posted: Mon Aug 16, 2004 5:11 pm Post subject: |
|
|
try:
Code: |
echo -e "\033[00;32m`cat /tmp/updates.txt`\033[00m"
|
Edit: BTW color definitions from dircolors -p:
Code: |
# 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
|
So to change the normal green (00;32m) to bold red (01;31m) you'd use:
Code: |
echo -e "\033[01;31m`cat /tmp/updates.txt`\033[00m"
|
|
|
Back to top |
|
|
dj_farid l33t
Joined: 14 Jun 2004 Posts: 613
|
Posted: Mon Aug 16, 2004 5:29 pm Post subject: |
|
|
Thanks! That seems to do the trick if I don't have the output piped to grep. Is there a way of getting around this?
If not, I could probably do another textfile that is already grepped... |
|
Back to top |
|
|
tomchuk Guru
Joined: 23 Mar 2003 Posts: 317 Location: Brooklyn, NY
|
Posted: Mon Aug 16, 2004 5:36 pm Post subject: |
|
|
Why not just:
Code: |
echo -e "\033[00;32m`grep ebuild /tmp/updates.txt`\033[00m"
|
I never got why people cat a file and then pipe it to grep instead of just using grep. |
|
Back to top |
|
|
bokkepoot Tux's lil' helper
Joined: 14 Mar 2003 Posts: 123 Location: The Hague, The Netherlands
|
Posted: Mon Aug 16, 2004 6:39 pm Post subject: |
|
|
The LDP has a chapter devoted to bash colourizing.
And people pipe the output of cat because they think pipes always come from the left hand side =) |
|
Back to top |
|
|
dj_farid l33t
Joined: 14 Jun 2004 Posts: 613
|
Posted: Mon Aug 16, 2004 6:55 pm Post subject: |
|
|
Thanks! I think that I got the hang of this now.
That link is very useful. |
|
Back to top |
|
|
|