Colorize Linux Shell Menu

Do you ever feel like you’re going blind because the prompt text color and the result text color are the same? Here’s how to colorize your shell prompt.

Open your favorite text editor (vim or nano), edit your ~/.bashrc, and add this at the end:

1
2
3
nano ~/.bashrc
# add this line:
PS1='\[\e[1;32m\][\u@\h \t \w]\$\[\e[0m\] '

The full set of color codes (the leading digit is the intensity: 0; for normal, 1; for bold/bright — so you have 16 colors, not 8):

1
2
3
4
5
6
7
8
0;30 black           1;30 dark gray
0;31 red             1;31 light red
0;32 green           1;32 light green
0;33 brown/yellow    1;33 yellow
0;34 blue            1;34 light blue
0;35 purple          1;35 light purple
0;36 cyan            1;36 light cyan
0;37 light gray      1;37 white

A few useful additions.

The PS1 line above is dense — here’s what each piece is doing:

1
2
3
4
5
6
7
8
9
\[ ... \]    tells bash "these characters are non-printing" so it computes
             prompt width correctly (otherwise long commands wrap weirdly)
\e[1;32m     ANSI escape: bold (1) green (32)
\u           current username
\h           short hostname
\t           current time, 24-hour HH:MM:SS
\w           full working directory
\$           '#' if you're root, '$' otherwise
\e[0m        reset all colors/attributes back to default

You can preview a color in your terminal without touching .bashrc by echoing the escape sequence directly:

1
2
echo -e "\e[1;32mhello in bold green\e[0m"
echo -e "\e[0;35mhello in purple\e[0m"

That’s the fast way to audition a color before committing to it in your prompt.

For background colors, the codes run 40 to 47 (same intensity rule applies). To make the whole prompt have a colored background, combine them:

1
2
PS1='\[\e[1;33;44m\][\u@\h \w]\$\[\e[0m\] '
# bold yellow text on a blue background

One portability note: hard-coded ANSI escapes work everywhere bash runs, but if you’re writing scripts that should adapt to different terminal types, tput is the modern, terminfo-aware alternative:

1
2
3
4
5
GREEN=$(tput setaf 2)
BOLD=$(tput bold)
RESET=$(tput sgr0)

echo "${BOLD}${GREEN}status: ok${RESET}"

tput queries the terminfo database for whatever terminal you’re actually on, so it gracefully degrades on terminals that don’t support color (it just emits empty strings). For your personal .bashrc, raw ANSI is fine and shorter; for scripts you ship to other people’s machines, tput is the polite choice.

After editing, reload your shell config with source ~/.bashrc (or just open a new terminal) to see the change.

Posted in Linux, Operating System, Ubuntu | Comments Off on Colorize Linux Shell Menu

Edit default Gnome-Terminal

Every time I open a shell terminal in my Ubuntu, I always think that the window size is too small. I always ended up resizing the shell window manually using the mouse. If you’re having this problem here is how to fix it permanently.

1
gnome-terminal --geometry=120x40

2026 update — what’s still relevant, and what’s changed. 🐧

–geometry is deprecated. Modern GNOME Terminal ignores the –geometry flag in most cases. The current way to set a default window size is in the GUI: Preferences → Profile → Text, then check “Initial terminal size” and set the columns and rows you want. The next terminal you open from your launcher will use that size.

Also worth knowing — newer distros are starting to ship different terminals by default. Fedora 39+ uses gnome-console (binary name kgx), and Ubuntu 24.10+ has been experimenting with ptyxis. They all do the same thing; just be aware that gnome-terminal may not be the default anymore.

Keyboard shortcuts most people don’t use enough:

  • Ctrl+Shift+T — open a new tab (instead of a whole new window)
  • Ctrl+PgUp / Ctrl+PgDn — switch between tabs
  • Ctrl+Shift+C / Ctrl+Shift+V — copy and paste (regular Ctrl+C sends SIGINT, remember?)
  • Ctrl++ / Ctrl+- — zoom in / out (great for screen sharing)
  • Ctrl+Shift+F — search the scrollback buffer
  • Ctrl+L — clear the screen (like running clear, but quicker)
  • Shift-click on a URL — open it in your browser without selecting it first

Profiles trick — colour your prod sessions red. Under Preferences → Profiles you can create multiple profiles, each with its own colour scheme, font, and starting size. A really useful pattern is to make a separate profile (say, Server SSH) with a red or dark-red background as a visual reminder that you’re not on your laptop anymore. Then launch into it directly:

1
gnome-terminal --profile="Server SSH" -- ssh user@server

It sounds gimmicky until the first time you almost rm -rf the wrong machine. 🚨

You can also have a Dark + Big profile for late-night work, a Light profile for screen sharing, and so on — switch via Terminal → Change Profile at any time. 💡

Posted in Linux, Ubuntu | Comments Off on Edit default Gnome-Terminal

Add an Existing User to an Existing Group on Linux

1
usermod -a -G GROUPNAME USERNAME
Posted in Linux | Comments Off on Add an Existing User to an Existing Group on Linux

Backup and Restore Postgres Using pg_dump and psql

This is how you backup your Postgres Database

To Backup

1
pg_dump --host=localhost --port=5432 --username=postgres --file=YOUR_FILENAME.sql YOUR_DB_NAME

There are other options such as if you’re interested only on the structure then you can add:

1
pg_dump --host=localhost --port=5432 --username=postgres --schema-only --format=p --create --inserts --file=YOUR_FILENAME.sql YOUR_DB_NAME

To Restore

1
psql -Upostgres -hlocalhost YOUR_DB_NAME < YOUR_FILENAME.sql
Posted in Database, PostgreSQL | Comments Off on Backup and Restore Postgres Using pg_dump and psql

Setting Session Authorization and Search Path

SET SESSION AUTHORIZATION jane;
SET search_path = schema1,schema2, schema3;
SELECT * FROM any_table_in_schema_1_2_or_3;

Posted in Database, PostgreSQL | Comments Off on Setting Session Authorization and Search Path

Implicit Casting in PostgreSQL

1
2
CREATE CAST(integer AS character varying) WITH INOUT AS IMPLICIT;
CREATE CAST (character varying AS integer) WITH INOUT AS IMPLICIT;
Posted in Database, PostgreSQL | Comments Off on Implicit Casting in PostgreSQL

Integer Array Casting in PostgreSQL

1
2
3
4
5
6
-- Rule: "_DELETE" ON sometable
-- DROP RULE "_DELETE" ON sometable;

CREATE OR REPLACE RULE "_DELETE" AS
    ON DELETE TO sometable DO INSTEAD  DELETE FROM _sometable
 WHERE _sometable.account_id = old.account_id AND (old.domain_id = ANY ((( SELECT get_visible_domains('DELETE'::text) AS get_visible_domains)::integer[])));
Posted in Database, PostgreSQL | Comments Off on Integer Array Casting in PostgreSQL

Tracing PostgreSQL Error Log

1
/pgsql/dev-db/tail -f postgresql.log
Posted in Database, Linux, PostgreSQL | Comments Off on Tracing PostgreSQL Error Log

Reset Sequence using PostgreSQL

1
SELECT setval('YOUR_SEQUENCE_NAME', (SELECT MAX(id) FROM YOUR_TABLE_NAME));
Posted in Database, PostgreSQL | Comments Off on Reset Sequence using PostgreSQL