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

Friday, 14 September 2012

postgres - run query on all tables

The following is an example in bash of applying a query to every table in the public schema on database template1:

for table in `psql -qAt -c "select tablename from pg_tables where schemaname in ('public');" template1` ; do  psql -c "alter table public.$table drop column if exists lastedit" template1 ; done

Thursday, 13 September 2012

set console title and prompt in bash

To set the title of your console window in a bash terminal put the following in .bashrc:

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}\007"

This will set the console title to user@host.

It can also be useful to have the host and pwd in the command prompt, that can be achieved with:

PS1='${HOSTNAME}: $PWD -> '

The achieve the same in a cshell window put the following in your .cshrc :

alias setprompt 'set prompt = "`uname -n`: `pwd` -> "'
alias cd 'cd \!*;setprompt;'