How to configure local terminal .bashrc in MobaXterm?

.bashrc is a script file placed in the user home directory and sourced while you start an interactive shell in Linux terminals, such as local MobaXterm or Cygwin. This script file can be edited or created to customize bash behaviour, for example, to define ENV settings, aliases, functions, call scripts, etc.

How do we configure the local bash terminal bashrc in MobaXterm?

Let us look at configuring the .bashrc file in your local mobaxterm.

How to configure local terminal .bashrc in MobaXterm

Step #1: Open your local bash terminal

  • Open your MobaXterm
  • From Terminal Menu, “Open New TAB
  • Click Start Local Terminal
  • Your terminal window will open

You would get a window something like the one below with a banner message,

[20XX-XX-XX 10:24.13]  ~
[admin.codetryout] >

Step #2: Open or create the file .bashrc

Edit .bashrc file using the command vim .bashrc
You can customize your settings there.

Step #3: Example customization

Let us enter a simple alias,

[admin.codetryout] > vim .bashrc
alias hello="hello codetryout world"

Step #4: Reloading the bashrc changes to the shell

You must reload the .bashrc file to make the changes available in your current shell. (Note: the changes will always be available when you open a new terminal/shell).
To reload .bashrc, use any one of the following methods,

. .bashrc

or

source .bashrc

Step #5: Testing your new bashrc

[admin.codetryout] > hello
hello codetryout world

For example, creating a bashrc edit by adding an alias to MobaXterm local bashrc:

In this example, we will add an alias to .bashrc, named code1. This alias will curl one web page from codetryout.com, Let’s try now:

# Adding a new entry to MobaXterm .bashrc

# Alias name: code1
/home/mobaxterm> echo 'alias code1="curl https://code.codetryout.com/ --output code.html"' >> .bashrc

Restart your MobaXterm or use the command: . .bashrc, as shown below, is used to reload your bash configurations that are in effect.

# Reloading the bashrc
/home/mobaxterm> . .bashrc

Testing the new alias from mobaxterm bashrc, calling your alias code1

/home/mobaxterm> code1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   311    0   311    0     0   2549      0 --:--:-- --:--:-- --:--:--  2549

Verifying your bashrc changes

/home/mobaxterm> cat code.html
<html>
  <head>
    <title>Code.CodeTryout.com</title>
  <body>
    <h1>code.codetryout.com</h1><br />
    This is a demo website for testing sample code experiments and demos at CodeTryout.com.<br />
    Please visit <a href="https://codetryout.com/">CodeTryout.com</a> for more information.
  </body>
</html>

Similarly, you may add anything that works on a shell to your bashrc, such as auto-login to a server using SSH, file copy using SCP, etc. Hope this helps