Question

Custom Path on Ubuntu start

Posted December 25, 2021 177 views
NginxUbuntu

I’ve been trying to customize my Ubuntu terminal.

My next self made task is for the Ubuntu terminal to load a specific path rather than the default on on opening.

To be more specific, I have Nginx installed and want to open that folder on start up.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
3 answers

Hi @teohristov,

In such cases, you can use the .bashrc file in your user’s root folder. In the .bashrc file you can add any command you want, you can create aliases and so on.

Basically, what you need to do is go to your user’s root folder:

cd ~
nano .bashrc

On the top of the file add

cd /path/to/nginx/installation

where /path/to/nginx/installation is your actual path.

Additionally, you do not have to limit yourself to only this command. Let’s say you want to list the directory as well, just for the kicks of it. You can add ls -lah in the same file underneath the cd command as well.

Usually, once you’ve created aliases or added such commands to your .bashrc file, you need to either reload it or open a new terminal(it reloads/loads by default on new terminal.). You can do it with:

source ~/.bashrc
  • Yes, that worked!

    You mentioned aliases, do these help with something else?

    • Hi @teohristov,

      Yep, aliases are pretty handy! You can say aliases are commands you create yourself from other commands.

      Let me give you an example. Let’s say you want to cd to folder and list it’s content( I know not the most useful example but can’t think of anything at the moment.) You’ll normally type to commands

      cd /path/to/folder
      ls -lah
      

      with the alias you can add the following to your ~/.bashrc file:

      alias goToDir='cd /path/to/folder; ls -lah'
      

      This will allow you to type in your terminal goToDir and it will execute the mentioned commands automatically.

Hi @teohristov,

Just to give you more information on what else you can achieve with changing/customizing your .bashrc file, you can also add colors to your terminal from there.

To add colors to the shell prompt use the following export command syntax:
’\e[x;ym $PS1 \e[m’
Where,

  • \e[ : Start the color scheme.
  • x;y : Color pair to use (x;y)
  • $PS1 : Your shell prompt variable.
  • \e[m : Stop color scheme.

You can change the color of the shell prompt by setting the PS1

To set a red color prompt, type the following export command:

export PS1="\e[0;31m[\u@\h \W]\$ \e[m "

Here is a list of colors:

  • Black 0;30
  • Blue 0;34
  • Green 0;32
  • Cyan 0;36
  • Red 0;31
  • Purple 0;35
  • Brown 0;33
  • Blue 0;34
  • Green 0;32
  • Cyan 0;36
  • Red 0;31
  • Purple 0;35
  • Brown 0;33