Walker News

Brighten Linux LS Command File Listing With LS_COLORS Trick

Redhat Linux and all other Linux distributions are capable to colorize ls command file listing. Depends on the LS_COLORS environment variable, the colorized directory or file listing of ls command might be hard to read on some dark background terminals. So, the tip and trick is to tweak the LS_COLORS environment variable.

As shown in the snapshot of SSH remote login session with Redhat Enterprise Linux, the first ls command file listing is really hard to read at all.

Snapshot of SSH remote login session with Redhat Enterprise Linux - Empty the default setting of LS_COLORS environment variable to lighten or brighten Linux ls command file listing on a dark background terminal.

In order to lighten or brighten the ls command output, you could simply empty the LS_COLORS environment variable setting!

Just type this command export LS_COLORS="" to remove all the file-type default color setting in LS_COLORS environment variable. Immediately, the Linux ls command file listing will looks brighter and easier to read. Although the folder and executable file-type are still colorized, some of the file-type colors will be missing – the gzipped tarball file-type turns from red to white color.

Why is this happen? This echo $LS_COLORS command has the answer!

There is another trick that works better. Instead of removing all the file-type-colors setup, all the existing file-type-colors setting found in the LS_COLORS environment variable will be tweaked to output a brighter Linux ls command file listing on dark background terminal.

Just type this command, which is rather long but is relatively simple and easier to memorize
echo $LS_COLORS | sed 's/00;/01;/g' | awk '{print "export LS_COLORS=\""$0"\""}' > LSCOLOR

will create a file called LSCOLOR in the current working directory path.

Next, type source LSCOLOR to execute LSCOLOR command file for the current working shell environment.

How to interpret that series of Linux commands?

1) echo command is used to display the value of $LS_COLORS environment variable
2) Pipe the echo command output to sed command to replace all the 00; found with 01;
3) Pipe the sed command output to awk command to write out a rather long, hard to remember export command in a file named LSCOLOR. You can view the file content by typing cat LSCOLOR.
4) The source command is critical to get thing done. It will execute the export command in LSCOLOR in the current working shell instead of a sub-shell environment.
When a Linux shell scripts executed, a sub-shell is spawned for the executing shell scripts. All the environment variables in parent shell are mutually exclusive with those in sub-shell. Once the shell scripts completely executed, the sub-shell will be destroyed. So, if source is not used, the export command will not effective in the parent (working) shell.

Alternative to the source command, you can also use the dot “.” to replace it. That’s to say, the . LSCOLOR command is identical to source LSCOLOR command.


Custom Search

  1. How To Setup Linux VNC Server In 3 Minutes – Walker News 11-10-07@11:48

    [...] VNC server works similar to Telnet or SSH daemon, except that it allows VNC clients running on diverse OS platforms to remotely access Linux Desktop Manager of the server itself, rather than the TTY text-based console! As such, most of Windows-to-Linux users prefer using VNC server than SSH daemon, who are generally favor on the vivid Desktop Manager (either KDE or Gnome) than the cold black-and-white TTY console! [...]

  2. Why VIM Editor Better Than VI Editor – Walker News 18-01-08@13:51

    [...] syntax color scheme for my standard (especially when I view the code over ssh session together with brighter LS_COLORS settings and syntax on). [...]

  3. Turn On View Hidden File Option In Windows Vista – Walker News 25-02-08@06:22

    [...] character. To view the Linux hidden files in command line, simple apply the -a option switch of the ls command. In Windows OS, the hidden file is controlled by the hidden file property. By default, the Windows [...]

  4. James Morris 01-05-08@17:47

    Nice little tip, just put it to effect, thanks.

  5. Using Linux Awk Regular Expression To Read Big Log File 06-02-09@00:25

    [...] I know there is a DB2 utility called db2diag to analysis db2 diagnostic log file content, I use a Linux command called awk with its regular expression function to extract diagnostic entries of the particular day [...]

  6. How To Quit From Telnet Login Prompt Immediately? 19-03-09@22:48

    [...] it will not cost much for recording it here as a reference. Question: You’re accessing Linux command prompt in front of server console or via remote access client (be it a insecure telnet or encrypted SSH [...]

2014  •  Privacy Policy