Making your command line more helpful and fun!

21.04.2016
The default terminal settings on most linux systems is to use colors to serve as hints about file types and permissions. For example, you'll see directory names in blue, executables in green, and file archives in red. And, if you don't want to see the colors -- like when they're just too distracting, you can turn them off easily. The command line colors are set when the ls command is aliased to an ls command that uses the --color option like this:

To turn off font colors for some period of time, you can just turn off the alias.

To turn off font colors all of the time, you can put the unalias command in your ~/.bashrc file or remove the alias command that sets it up in the first place, though that might be in your ~/.bashrc file or some system file.

You can also make individual changes to your font color palette. Say you don't like seeing blue as the font color that displays the names of directories. Maybe your background color is a close blue. You can change the color used for just directories with a command like this:

So, where did that come from The di in that command signifies directories. It and other particular file types that you can specify are listed here:

The 35 in the command indicates the color -- 35 means purple. Some of the options in the list below can be combined. For example, you could use a purple font with a green background if you use di=35;42.

Here is a list of your options, though I have to admit to some of these color combinations combined with flashing would probably make me dizzy.

Another cute trick that I picked up online is making the color of your prompt change depending on whether the command you just entered completed successfully or not. This trick uses some of what we've seen above (e.g., selecting the right font colors), but adds a function to your ~/.bashrc file that formats your prompt after evaluating the exit status of your last command.

Add a function like this to your ~/.bashrc file and your prompt will go from green (normal) to red (something is wrong) when you type a command that fails for some reason.

Notice that the RED and GREEN settings correspond to colors listed above. If the exist status is 0 (success), your prompt will be green. If your exit status is anything else (error), your prompt will be red. You can customize the colors by changing the the RED and GREEN settings and then applying them in the lines that follow.

The prompts in this post's image were done using nearly the same settings, but with the additional words "ok" and "OOPS!". Here are the lines for those settings -- maybe just right for the next Unix beginner you add to your staff.

Don't forget that you can also customize your prompt in other ways. You might, for example, want to include the system's name in the prompt so that you remember what system you are logged into. Use a \h for that -- PS1="${GREEN}\h>${OFF} " or add your username with \u to help you remember what account you're currently using -- PS1="${GREEN}\u@\h>${OFF} ".

Messing around with your prompt and screen colors can help remind you what you're doing an where -- particular if you, like me, often find yourself working on several systems at a time and jumping from window to window.

(www.computerworld.com)

Sandra Henry-Stocker

Zur Startseite