Sunday, January 6, 2013

How do I set Linux terminal to change font color/size for my commands vs. output?

Q. I would like terminal to display my commands in a different color or size (so that they stand out) than the output after running the command. Any suggestions?

A. Most unix shells (including BASH, which is probably what you're using if you're on a modern Linux distro) support customizing your shell prompt using the PS1 environment variable. While you _could_ set up colours in your terminal shell program (assuming it supports this), I'd recommend the PS1 approach, because: 1) It'll work regardless of which terminal shell program you use, and 2) if you connect to multiple machines, then you can easily make this change on all of them by just copying the BASH config onto each machine.

Typically you'd set the value of PS1 in your bash profile or rc file file (I'd recommend .bashrc in your home-directory). From that point forward, anytime you open up a terminal, it'll show whatever prompt you set up in PS1. You can customize what text appears (e.g. the hostname, current working directory, etc), and also set colours. For example, here is what I typically have at the end of my .bashrc file for my custom prompts:

# Shell prompt and fields
export PS1_USERNAME='\[\e[1;36m\]\u\[\e[m\]\100'
export PS1_HOSTNAME='\[\e[1;33m\]\h\[\e[m\]:'
export PS1_DIR='\[\e[1;32m\]\w\[\e[m\]'
export PS1_PROMPT='\[\e[1;31m\]\$\[\e[m\]'

export PS1='['${PS1_USERNAME}${PS1_HOSTNAME}${PS1_DIR}'] '${PS1_PROMPT}' '


What this shows is a prompt like the following (assuming I'm user "jsmith" on machine "bigbox" in directory "/var/log":

[jsmith@bigbox:/var/log] #

Where the username's in cyan, the machine name's in yellow, the directory's in green, and the # character's in red. Actual commands I type in are in the standard white (you can change this by not resetting the colour at the end of the PS1 prompt).

Output is harder to change the colour for. So if you want your typed commands to be coloured differently than your output, simply change the colour of your typed commands in PS1 instead.

You can create incredibly customized (and complicated) prompts with a bit of effort. Take a look at the two links in my Source(s) section below, for some good help on this subject.

Hope this helps;

Wire

Whats the terminal command for linux mint 4 to access lost and found?
Q. I have linux mint 4. I need to wipe my computer off of junk and reinstall. I also want to upgrade my hardrive and reinstall linux mint 7, and the latest ubuntu. I want to get the junk off manually, search and destroy, and then uninstall. I need that harddrive for my other computer, can you help me out? Linunx mint is the way to go by the way.

A. If you are looking to delete and format the Drive with Linux Mint 4.0 on it I recommend you use Gnome Partition Editor (GParted). For this operation you can run off any Ubuntu or Mint LiveCD as Gnome Partition Editor is included

GParted User Manual
http://gparted.sourceforge.net/docs/help-manual/C/gparted_manual.html

LINUX MINT 7

Linux Mint 7 Release notes
http://www.linuxmint.com/rel_gloria_whatsnew.php

Linux Mint 7 (32bit) Download
http://www.linuxmint.com/edition.php?id=38

The Perfect Desktop - Linux Mint 7 (Gloria)
http://www.howtoforge.com/the-perfect-desktop-linux-mint-7-gloria

UBUNTU 9.04

Ubuntu 9.04 Technical overview
https://wiki.ubuntu.com/JauntyJackalope/TechnicalOverview

Ubuntu 9.04 Download
http://releases.ubuntu.com/jaunty/

The Perfect Desktop - Ubuntu 9.04 (Jaunty Jackalope)
http://www.howtoforge.com/the-perfect-desktop-ubuntu-9.04

ALTERNATIVE

Linux Mint is certainly the way to go however my preference is Linux Mint 6

Linux Mint 6 Release notes
http://www.linuxmint.com/rel_felicia.php

Linux Mint 6 Download
http://www.linuxmint.com/edition.php?id=31

The Perfect Desktop - Linux Mint 6 (Felicia)
http://www.howtoforge.com/the-perfect-desktop-linux-mint-6-felicia


LUg.

Is it morally or ethically wrong to modify a windows computer to accept linux terminal commands in CMD?
Q. For example,
Run>Terminal>ifconfig /all

A. Nope, although Cygwin is probably a more practical alternative. It's still Windows, after all.




Powered by Yahoo! Answers

No comments:

Post a Comment