---
title: 'A simple but handy Bash function: console'
date: 2011-12-28 03:30
slug: a-simple-but-handy-bash-function-console
categories:
- Code
tags:
- scripting
- terminal
---

Here's a quick riff on an older bash alias I use which will allow you to easily scan system messages from Terminal.

I've long had an alias in my `~/.bash_profile` called `console`. It simply tailed the system log with 'alias console=`tail -f /var/log/system.log'.
	
### Bam
	
I decided to amp it up a little for added convenience. The function below allows me to add additional arguments which are translated into a regular expression for filtering the log output. Arguments, separated by spaces on the command line, are joined into a regular expression as OR matches. You can specify as many as you like to track each as a keyword. It's case insensitive and you can use basic regular expression syntax in each parameter. Examples:

	$ console byword

	$ console usbmuxd servermgrd
			
	$ console mark(ed|y) multimarkdown composer
	
`console` with no arguments will still just tail the log with no filter.

### The function

Just stick this in your `~/.bash_profile` file, run `. ~/.bash_profile` and try it out.

	function console () {
	  if [[ $# > 0 ]]; then
	    query=$(echo "$*"|tr -s ' ' '|')
	    tail -f /var/log/system.log|grep -i --color=auto -E "$query"
	  else
	    tail -f /var/log/system.log
	  fi
	}

If you want to track more than just the `system.log` file, you can just add additional filenames, separated by a space, after system.log for each `tail` command in the function.

There, that was handy.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
