How to execute a specific command on opening a terminal

I would like to execute the shell command "cmatrix" whenever I open a terminal. How to go about achieving this?


Solution 1:

You can add cmatrix command in your ~/.bashrc file located at home folder:

echo 'cmatrix' >> ~/.bashrc 

NOTE: Please ensure that you use >>, the append operator. If you use >, it will replace your whole ~/.bashrc with cmatrix only.

Solution 2:

Because you tagged your question with gnome-terminal, you can also use a a custom command for your gnome-terminal profile. The advantage, the command is executed only for a specific profile and not always when the bash is started somewhere.

But first install dconf-editor. If you make a mistake in the steps below, you will need this tool

sudo apt-get install dconf-editor

Now open gnome-terminal and edit your profile settings and use this command

sh -c "cmatrix;bash"

as you can see in the screenshot below. If you don't use the bash, replace bash with your shell.

enter image description here


If you made a mistake and gnome-terminal is unusable, use use dconf-editor to correct your problem:

Start dconf-editor and navigate to the settings of GNOME terminal and change the values for custom-command and use-custom-command in the settings for your gnome-terminal profile