Customizing Your Shell

Today I will be showing you how to customize your shell, I will use zsh and bash for these examples since those are the 2 shells I usually use. So lets jump right in shall we?

What Shell Am I Running?

You can find out what shell you are running by using the following command.

What Shell Am I Running Linux

Editing Bashrc And Zsh.rc Files

These two files as-well as others such as .bash_profile for example are run whenever you open a terminal or ssh onto a different host. You can customize them to make your life much easier by adding shortcuts, functions, and even changing your prompt. For the purpose of this guide I will be using Bash simply because it is the most common shell. If you are using ZSH then simply change the commands below to .zshrc instead of .bashrc.

There are plenty of ways you can edit your files ranging from a graphical text editor for example gedit on desktops to nano or vim on servers. We will use nano simply because it is easier for most people, although vim has syntax highlighting. To open your .bashrc file in nano run the following command and to save when you are finished press ctrl+x and then y.

Adding Aliases To Bash Profile

Adding aliases can make your life much easier when it comes to repetitive commands. For example if I constantly check a log for specific errors then I could add an alias like the one below to my .bashrc file.

After adding this alias I would simply run “check” and it will automatically run my grep command. You can also add more than one command to an alias by using a semicolon “;” or “&&” for example.

Adding Functions To Bash Profile

By adding functions to your bash profile you can accomplish a-lot of repetitive tasks that aliases just won’t do the trick for quickly. With functions you can also pass arguments and do things like for loops and much more. To pass arguments you should use the “variable” $1 for the first argument, $2 for the second, and so forth. Here is an example:

Add Function To Bashrc Linux

Customize Your Shell Prompt

You can customize your shell prompt to suit your specific needs by adding just one line to your .bashrc. I will give you an example below to get you started however there are plenty of extra options you can add to get your desired effect. I will start this part of the post off by showing you the prompt that I am currently using. If you need to know the other options such as adding hostname or the date, please refer to this link as it is full of great information about PS1 specifically.

Edit PS1 On Linux

I hope you enjoyed this post, please do not forget to like/share/comment as it will help this blog grow. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *