Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Tuesday, May 18, 2010

My bashrc changes

Apart from the traditional personal alias lines, here are the commands I do like to add in the /etc/bashrc of every server.

The first one is dedicated to everybody who uses to tease me with the song "linux is only black and white". It may be less visual that other OS, but we can manage to add some colours to make it easier (and prettier) :
PS1='[\[\033[0;31m\]\u\[\033[0m\]@\[\033[1;31m\]\h \[\033[0;35m\]\W\[\033[0m\]]\$ '

Second set of commands is to get a more powerfull bash history. Knowing what has happened on your server is fine, but knowing when it happened is also a very valuable information. And let's add some colours again :
MY_BASH_BLUE="\033[0;34m" #Blue
MY_BASH_NOCOLOR="\033[0m"
HISTTIMEFORMAT=`echo -e ${MY_BASH_BLUE}[%F %T] $MY_BASH_NOCOLOR `
HISTSIZE=20000
HISTFILESIZE=20000

Saturday, February 20, 2010

My favourite bash shortcuts

As a system administrator, the bash may be the linux tool you use most. So it may be a good idea to know a bit about the shortcuts that may speed up your job.
Here are my favourite ones :
Ctrl-a , to go to the beginning of the line
Ctrl-e , to go to the end of the line
Alt-b , to move backward one word
Ctrl-u , to delete everything to the left of the cursor
Ctrl-w , to delete the previous word

cd - , to go back to the previous directory

Ctrl-r , to search a previous command in the bash history. This, is a MUST shortcut. The one I prefer. Just type Ctrl-r and then, a few letters of a command that is in the history to find it and be able to execute it (the bash will do a pattern matching on the commands in your history). To look further in the history, you can type many times Ctrl-r.
Alt-. , to print the last argument of the last command. You can type many times this shortcut to look for an argument further in your history.

^foo^bar, to substitute the "foo" pattern in your previous command by the "bar" pattern and execute it.