Back To School: Terminal Tips

September 30th, 2006 by peasleer

Over the past week I’ve been doing a lot of tweaking to my shell environment, and helping others do the same. I’ve come across a few fixes and common things that people might find useful, so here we go!

The first is a script snippet to change your shell to bash on login. It only works in some environments, but for those of you who are desparate, throw this in your .cshrc:

if ($?prompt != 0 ) then
     setenv SHELL_NAME /bin/bash
     if ($SHELL != $SHELL_NAME ) then
          set shell = $SHELL_NAME
          setenv SHELL $SHELL_NAME
          exec $SHELL
     endif
endif

One of the more frequent questions I answer is how to get around having to type ‘./’ to run programs in your current directory. The answer is in editing your PATH variable. Throw the following in your shell’s rc file:

export PATH=.:${PATH}

In order to make use of colors in your terminal, you first need to be using a terminal that supports them, and then tell the tty so. To do this, you need to change your SHELL variable to something that supports colors:

export TERM=xterm-color

To make full use of your color supporting terminal, we can make use of newer versions of grep and ls to make output use colors. While we are doing this, we might as well make things more human friendly, so let’s make du and df print out human friendly data. Aliasing automatically replaces words you’ve specified in your .bashrc with the strings they’ve been aliased to, and allows us to do all of these things at once. Here are some examples:

# Aliases for making the command line human friendly
alias df='df - h'
alias du='du -h'      # Make du and df always report human readable data
alias ls='ls --color'     # If your version of ls supports it, use colors
alias grep='grep --color'     # If your version of grep supports it, use colors

Finally, some misceallaneous tips. The first clears the *extremely* annoying issue of having a command line that doesn’t support backspaces or other common keys. Put this in your shell’s rc file:

stty sane

Some environments allow other users logged into the same machine as you to send messages to your terminal. This is annoying if your peers think it is funny to disrupt your debugging. To turn it off, just issue the following at the command line (to disable it for that session) or in your shell’s rc file as a permanent fix:

mesg n

And if you want to be one of those kids that interrupts someone else, don’t just write them stupid messages and giggle about it. It is much more entertaining to send an endless amount of gibberish to their screen. The following script will pipe data from /dev/random to another user’s terminal until you kill it:

#!/bin/bash
echo "Enter a username: "
read user
dd if =/dev/random | hd -c | write $user

0 Responses to “Back To School: Terminal Tips”

Feed for this Entry Trackback Address
  1. No Comments

Leave a Reply