Changing terminal colors in Ubuntu Server

29

Solution 1

You'll need to configure your LS_COLORS export in your ~/.dir_colors (system wide at /etc/dir_colors)

See here for documentation: http://manpages.ubuntu.com/manpages/karmic/man5/dir_colors.5.html

::EDIT::

To make it stick:

  1. append this to your ~/.bashrc
    if [ "$TERM" != "dumb" ]; then
      [ -e "$HOME/.dir_colors" ] && 
      DIR_COLORS="$HOME/.dir_colors" [ -e "$DIR_COLORS" ] ||
      DIR_COLORS="" 
      eval "`dircolors -b $DIR_COLORS`" 
      alias ls='ls --color=auto'
    fi
  1. create/edit your ~/.dir_colors,

    for example with dircolors --print-database > .dir_colors

  2. Then force a read of your .bashrc file with:

    $: source ~/.bashrc

  3. Everything should be pretty.

Solution 2

How to change the colors of file listings in Linux shells

Summary

Linux interactive terminals (aka ssh terminal, konsole or console login) automatically choose colors for 'files', 'directories', 'hard links', 'soft links', 'pipes', 'sockets', 'filesystems', etc. You see these colors displayed when you type 'ls' to list file contents. Directories are usually blue, files are usually light grey. Different foreground/background colors are used for various kinds of filesystem objects.

Problem:

Your terminal displays directory links as dark blue when you type 'ls', and you want it to be light cyan so you can read it better.

Solution

Using your favorite editor, open this file: /etc/DIR_COLORS You should see something like this:

#NORMAL 00      # no color code at all
#FILE 00        # regular file: use no color at all
RESET 0         # reset to "normal" color
DIR 01;34       # directory
LINK 01;36      # symbolic link.  (If you set this to 'target' instead of a
                # numerical value, the color is as for the file pointed to.)
MULTIHARDLINK 00        # regular file with more than one link
FIFO 40;33      # pipe
SOCK 01;35      # socket
DOOR 01;35      # door
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # ... and the files they point to
SETUID 37;41    # file that is setuid (u+s)
SETGID 30;43    # file that is setgid (g+s)
CAPABILITY 30;41        # file with capability
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44    # dir with the sticky bit set (+t) and not other-writable

Notice the 4th line down starting with: "DIR". That is the color for your Directory links. If you want more info about what the codes mean visit this site:

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html

Notice the code for DIR is '01;34'. the 34 means dark blue. You may be tempted to just edit this file /etc/DIR_COLORS right where it sits. DON'T do that. Because then you'll be changing the colors for EVERYONE who logs into this computer. You'll have to make a copy of this in your own directory so only your login is affected.

How to change the directory colors for your user

Copy /etc/DIR_COLORS into your home directory with this command:

cp /etc/DIR_COLORS /home/yourusername/.dir_colors

Open up your /home/yourusername/.dir_colors in your favorite editor and edit the line that looks like this:

DIR 01;34       # directory

And change it to this;

DIR 01;36       # directory

34 is the code for blue, 36 is the code for cyan. Save the /home/yourusername/.dir_colors You'll have to logout/login for the settings to take effect. (sourcing your profiles won't suck in the changes). Once you logout/login, run the command 'ls'. The directories should show up with cyan instead of blue. Like this:

Before:

enter image description here

After:

enter image description here

Share:
29

Related videos on Youtube

Rossen Hristov
Author by

Rossen Hristov

Updated on September 17, 2022

Comments

  • Rossen Hristov
    Rossen Hristov almost 2 years

    EntityFramework 5.0

    Suppose I have the following setup:

    public class Book
    {
        public int ID {get; set;}
        public string Title {get; set;}
    
        [InverseProperty("Books")]
        [Required]
        public Author Author {get; set;}
    }
    
    public class Author
    {
        public int ID {get; set;}
        public string Name {get; set;}
    
        public virtual ICollection<Book> Books {get; set;}
    }
    

    Then in my code I create a new Book and I do this:

    author.Books.Add(newBook);
    

    How can I have the Book pick-up its Author automatically instead of having to write this every time:

    newBook.Author = author;
    

    I want the child entity to pick up its parent automatically when added to the parent's collection.

    Is this possible? Fluent mapping maybe?

    Or do I have to maintain both sides of this bi-directional relationship myself?

    • gWaldo
      gWaldo almost 12 years
      Downvoted per the first down-vote criteria: "This question does not show any research effort"
    • Josh K
      Josh K almost 12 years
      @gWaldo Thanks for downvoting a two year old questions. Really, great job.
    • gWaldo
      gWaldo almost 12 years
      Sadly your question did not improve with age.
    • user5870571
      user5870571 almost 5 years
      This belongs on super user. Changing colors in a terminal program is not related to managing a business and @gWaldo is right about it appearing to lack any research effort.
  • David Rickman
    David Rickman about 14 years
    See edit in comment.
  • David Rickman
    David Rickman about 14 years
    If he is running the server edition, then there shouldn't be a desktop environment.
  • Dennis Williamson
    Dennis Williamson about 14 years
    According to the man page you linked to, those files are ignored by GNU dircolors. On Ubuntu, your ~/.bashrc file should have a line like eval "dircolors -b". You could try changing it to eval "dircolors -b ~/.dir_colors" and create that file by doing dircolors -p > ~/.dir_colors` then edit it to change particular file types.
  • Dennis Williamson
    Dennis Williamson about 14 years
    @freedom_is_chaos: But he mentions xterm and "gnome".
  • David Rickman
    David Rickman about 14 years
    What files? .bashrc is your user-configurable bash shell. .dir_colors is your user configurable file for dircolors. Making it stick via the .bashrc file is going to be the only way to have it stick with every login unless you go global for everything. In which case, I don't want your pink directory colors.
  • David Rickman
    David Rickman about 14 years
    I figured he was guessing more at what shell he is running rather than program because he was running the server version.
  • Dennis Williamson
    Dennis Williamson about 14 years
    "/etc/DIR_COLORS (Slackware, SuSE and RedHat only; ignored by GNU dircolors(1) and thus Debian.) System-wide configuration file." (it says the same thing for ~/.dir_colors) However, your code above (and the code in my comment) takes care of this.
  • Josh K
    Josh K about 14 years
    There is no desktop environment, I only mention xterm and gnome because those are various references to things I found in my search for this.
  • Josh K
    Josh K about 14 years
    What should I put in ~/.dir_colors?
  • David Rickman
    David Rickman about 14 years
    @Josh K: This link gives the exact directions I have for this with a few examples listed. See ubuntuforums.org/showthread.php?t=41538
  • towi
    towi almost 11 years
    The "if file exists, then default..."-logic did not work for me. But One can specialize it to a simple if [ "$TERM" != "dumb" ]; then eval $( dircolors -b $HOME/.dir_colors ) fi