Individualize the Bash

If you work a lot in the BaSh, you will appreciate the ability to create own preferences and shortcuts. Those will make the terminal an even more powerful tool.

You can edit you personal settings of the Bash in one of two files (depending on your system) within your home-directory. The .bashrc or the .bash_profile. The leading dot means the files are hidden. To show hidden files, you to tell ls to show all files:

cd ~
ls -a

The first line changes into your home-directory (in most cases you can also just type cd). The second line shows all files, including hidden ones.

You can edit the Bash-profile-file in every texteditor you like.


An alias is a kind of shortcut. With an alias you can create your own bash-commands. Let's start with a simple example: Imagine you want to show all files in a directory as a list over and over. You would then enter the following:

ls -lah

ls to list, -l to get a detailed list, -a to also show hidden files, -h to show the information in a human readable format. Of course you could enter this command alle the time, but also could create an alias.

You are free to add you alias-definition anywhere in the bash-profile-file. I prefer to add them on top. So, let's create our alias by adding the following line:

alias ll='ls -lah'

That's it. We just created the alias ll which will execute our special ls-command we used above.

Don't worry, if you saved your bash-profile but the alias isn't working. The .bashrc or the .bash_profile are only parsed once when your login-session is initialized. So you have to quit your terminal-application and start it again or, if you are working directly on the console, you have to logout an -in again.

Hint I don't know if this works on every system, but you may also use the reset command to initalize a new session.

You can now add as many alias-definitions as you like. Everything you can do in the bash can be an alias. But watch out! Avoid using alias-names which may already be bash-commands to avoid trouble.


By the way. If you are working git a lot in your terminal, you can define special git-alias, too! You can read here, how it works and what to do.

Individualize the bash-prompt

You can upgrade your bash-prompt with a lot of usefull information. I prefer a minimalistic approach. Especially on my desktop-computer. I am always logged in a the same user and I don't need the hostname to be shown all the time. So I modified my bash-prompt to look like so:

It only shows the current directory I am in. Let's change the directory to make it a bit more visual:

I am in the directory _PROJECTS. As you can see only the current directory is shown not the whole path. That's because I want my prompt to be as short as possible.
Because I am working a lot with git, I extended the prompt to show the actual branch as soon as I am in a git repository:

You can individualize you prompt, by adding (in my case) the following line to the bottom of you bash-profile-file:

PS1="\[\033[1;33m\]\W\[\033[0m\] \[\033[1;32m\]\[\$(git_prompt_info)\]\[\033[0m\]$ "

To get the git-part up and running, you need to add a special function to your bash-profile. Btw. there is a nice webtool to create your own prompt.

Search your bash-history

If you want to look for already used commands you can easily do so by hitting ctrl+R and start typing the command. You will then get suggestions based on already used commands. If you like the search through the history chronologically you can use this snippet.

More ideas?

You have some more ideas or hints on how to make your bash-life more comfortable? Post a comment or ping me on twitter.

What you could do now

If you (don't) like this post, you can comment, write about it elsewhere, or share it. If you want to read more posts like this, you can follow me via RSS or ActivityPub, or you can view similar posts.