Changing colors for user, host, directory information in terminal command prompt

1

Is it possible to change the colors in the command prompt for the [email protected], as well as the the current directory and command parts of the prompt display?

I've already seen something like this done by OSX users, but I don't know how to do the same thing in gnome terminal (I can only change foreground and background colors).

It'd be very useful when, for example, trying to compile programs that have errors, since long, unformatted messages make it hard to distinguish which lines are commands and which are output.

Answers 3

For details, see this detailed HOWTO.

In short, you can alter the prompt by editing the $PS1 environment variable. There's so much to say here, that I'll just show you my prompt and refer you to the link above for more details.

The color-related parts are in the function setPrompt:

# This function from:...
0 0
2

You can try the BashrcGenerator. This is by far the easiest way to get a prompt like you want. I've noticed that the colors defined here may be different from your own system, but that's a small issue. With the generated code you can change the colors yourself.

Server user:

export PS1="\[\e[01;37m\][\[\e[0m\]\[\e[01;32m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;34m\]\h\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;37m\]\t\[\e[0m\]\[\e[01;37m\] \W]\\$ \[\e[0m\]"

Server root:

export PS1="\[\e[01;37m\][\[\e[0m\]\[\e[01;31m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;34m\]\h\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;37m\]\t\[\e[0m\]\[\e[01;37m\] \W]\\$ \[\e[0m\]"

And if needed you can change hostname color to reflect different type of servers.

I use different format for my local computer:

export PS1="\[\e[01;33m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;36m\]\h\[\e[0m\]\[\e[00;37m\] \t \[\e[0m\]\[\e[01;35m\]\w\[\e[0m\]\[\e[01;37m\] > \[\e[0m\]"

My favorite...

0 0
3


Question:

Is it possible to change the colors in the command prompt for the user@computer, as well as the the current directory and command parts of the prompt display?

I've already seen something like this done by OSX users, but I don't know how to do the same thing in gnome terminal (I can only change foreground and background colors).

It'd be very useful when, for example, trying to compile programs that have errors, since long, unformatted messages make it hard to distinguish which lines are commands and which are output.


Solution:1

You can edit the settings editing the file: ~/.bashrc.

Open the file: gedit ~/.bashrc.

Look for the line with #force_color_prompt=yes and uncomment (delete the #).

Look for the line below if [ "$color_prompt" = yes ]; then that should looks like:

...
0 0
4
Bash terminal: change color of directories

Bash terminal: change color of directories #

and the current working directory path. Because blue on black is hard to read.

Change the color of directories in bash:

If you don't already have an /etc/DIR_COLORS file, create one: $ sudo dircolors -p > /etc/DIR_COLORS
(See Configuring LS_COLORS for information on multi-user options) Open /etc/DIR_COLORS in a text editor and change DIR 01;34 to DIR 01;33 to change the default blue to yellow. More color codes. In ~/.bashrc, change eval "`dircolors -b`" to eval "$(dircolors /etc/DIR_COLORS)" Reload .bashrc to see the result: $ source ~/.bashrc

Change the bash prompt's current working directory path color:

In ~/.bashrc, comment out every line between:
# set a fancy prompt (non-color, unless we know we "want" color)
and:
# Comment in the above and uncomment this below for a color prompt Uncomment the next line and change 01;34m to 01;33m. It should look...
0 0
5
...
0 0
6

This is the complete list of Command Prompt commands.

Letter Command Function a ADDUSERS Add or list users to/from a CSV file ADmodcmd Active Directory Bulk Modify ARP Address Resolution Protocol ASSOC Change file extension associations• ASSOCIAT One step file association AT Schedule a command to run at a specific time ATTRIB Change file attributes b BCDBOOT Create or repair a system partition BCDEDIT Manage Boot Configuration Data BITSADMIN Background Intelligent Transfer Service BOOTCFG Edit Windows boot settings BROWSTAT Get domain, browser and PDC info c CACLS Change file permissions CALL Call one batch program from another• CERTREQ Request certificate from a certification authority CERTUTIL Utility for certification authority (CA) files and services CD Change Directory - move to a specific Folder• CHANGE Change Terminal Server Session properties CHKDSK Check Disk - check and repair disk problems CHKNTFS Check the NTFS file system ...
0 0
7

When you have such an attractive interface, using Command Prompt might seem like a old fashioned thing. When you can easily navigate to a location or access different settings in your PC customize them, why go for complex commands and a dull interface? Well, it might not be as bad as one might think. Command Prompt might be a bit complex, but it makes all the manual tweaking just a single command’s work. The current users of Command Prompt understand how powerful it is, which is why they don’t mind learning few tricks or commands to take care of daily work in a snap. So learning at least basics of Command Prompt is worth saving few seconds of extra work everyday.

We have created this list of Command Prompt commands and tricks that may help you work better. Whether you just started using Command Prompt or you are a regular user, you should be able to find a trick to ease things up a bit.

Update: If you want the latest Command Prompt tricks, you can also check out...

0 0
8

In Windows command prompt, we can change the directory using the command cd . Both cd and chdir refer to the same command. Syntax of this command is explained below with some examples.

Change directory

When we launch command prompt, the default directory it opens with is C:\Documents and Settings\logind. This is in Windows XP. In Windows 7 command prompt opens up with the directory C:\Users\loginid. Now let’s say you want to traverse to the directory C:\Windows\System32. The command for this is given below.

C:\>cd C:\Windows\System32

(or)

chdir C:\Windows\System32

Change to a directory with spaces in the name

In Windows, we can have spaces in the directory names. cd command can interpret the space correctly. So we do not need to enclose quotes around the directory name, as with most of other windows commands. An example is shown below.

C:\>cd C:\Documents and Settings\cmdadmin C:\Documents and Settings\cmdadmin>

Change drive and directory...

0 0
9

Geeks and experts all love the Command Prompt because of the advanced tasks and commands you can run in it. But that doesn’t mean that it’s only useful for experts - after all, every expert was a novice in the beginning. And Command Prompt is not built only on advanced commands, but also on simple commands designed to perform basic operations. In this article we will show you how to execute commands like changing the working folder, viewing the contents of a directory, creating and renaming folders, copying, deleting files and folders, and launching any application from the Command Prompt. We will also see how to get help when using this tool.

NOTE: The information shared in this tutorial applies to Windows 10, Windows 8.1 and Windows 7. Note that, for simplicity, we will use screenshots taken only in Windows 10.

How to navigate between folders

The first command from the list is CD (Change Directory). This command enables you to change the current folder or,...

0 0
10

In the bash shell, the command prompt is the text shown when you are being prompted for input. On most systems, it looks like this:

In the prompt you can have information before you run any commands. For example, the above prompt shows you:

who you are (a user named user) where you are (a computer named myhost) what your working directory is (~, which is an abbreviation for your home directory)

Perhaps most important is the dollar sign ("$"): this is a special character that indicates that you are logged in as a non-root user. If you were currently logged in as root, this character would be a pound sign ("#") instead.

The string representing the prompt is stored in the special environment variable named PS1. For the prompt above, its value looks like this:

"\[email protected]\h:\W\$ "

There are four special characters in this string: \u, \h, \W, \$. These are escaped character sequences that are replaced with actual values every time the prompt...

0 0
11
CommandDescriptionAppendThe append command can be used by programs to open files in another directory as if they were located in the current directory. The append command is available in MS-DOS as well as in all 32-bit versions of Windows. The append command is not available in 64-bit versions of Windows.ArpThe arp command is used to display or change entries in the ARP cache. The arp command is available in all versions of Windows.AssocThe assoc command is used to display or change the file type associated with a particular file extension. The assoc command is available in Windows 8, Windows 7, Windows Vista, and Windows XP.AtThe at command is used to schedule commands and other programs to run at a specific date and time. The at command is available in Windows 7, Windows Vista, and Windows XP. Beginning in Windows 8, command line task scheduling should instead be completed with the schtasks command.AtmadmThe atmadm command is used to display information related to asynchronous...
0 0
12


If you can and your .bashrc is messed up, you can try to source the file in /etc, usually /etc/bash_profile or /etc/bashrc will get you a normal prompt again. Then proceed in editing your users own .bashrc accordingly.

Open a new terminal. If you sourced it on the previous terminal, a new terminal will use the default file to source from. You can also try logging out and back in as well. Or try typing reset in the terminal and hitting enter.

Perhaps it's time to reboot into single user mode and restore the original .bashrc. Or if you are a regular user, just su (or sudo if you setup sudo) to become root to restore or create a useful .bashrc file for the user.

Nope, booting into single user mode should allow you to fix this issue. Are you logged in as root and messed up root's .bashrc? If not, ctrl-alt-F2, login to console as root, fix issue for user. If you are root with no other created users, reboot into single user mode by passing single as an...

0 0