How to create Bash aliases in Fedora

Creating your own Bash aliases is a relatively easy process. That said, I recently switched my desktop linux distribution from Debian to Fedora and there are subtle differences. On Debian, the default .bashrc file has the following entry:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

The above tests as to whether or not the .bash_aliases file exists in the user's home directory and if it does exists, it loads any aliases held within it. I like the simplicity of this.

It works slightly differently with Fedora, where the default .bashrc file has this entry:

# User specific aliases and functions
if [ -d ~/.bashrc.d ]; then
	for rc in ~/.bashrc.d/*; do
		if [ -f "$rc" ]; then
			. "$rc"
		fi
	done
fi

The above tests for the existence of the .bashrc.d directory within the user's home directory, before attempting to load every file within that directory. I like this approach too.

So, to create a Bash alias under Fedora, first create the .bashrc.d directory in your home directory (it does not exist by default) and then create a new file in that directory. The file can be named anything, but you probably want to call it something relative, like aliases. This can be achieved with the following command.

mkdir -p ~/.bashrc.d && touch $_/aliases

Edit the newly created aliases file and write your aliases as required.

None of this is super important as you can edit your .bashrc file to load your aliases however you want, I just find these little nuances between Linux distros quite interesting.

bash debian fedora linux

Comments

New Comment

If you have a comment you'd like to share, feel free to leave it below. I moderate all comments before they are published. Markdown is enabled. See syntax for help.


I'll never share your email with anyone else.

Blog

I mostly try to write non-opinionated posts about web development and Linux - reminders about how to complete tasks and get stuff done etc.

For short-form posts, see my status page.

Subscribe

Click the link below to subscribe to my Blog feed in your favourite news reader client:

RSS feed

Philip Newborough and a donkey enjoying a beer.

About

My name is and I’m a full stack web developer living and working in Lincoln, England. This website (philipnewborough.co.uk) serves as my personal homepage. When I’m not working with tech, I love to ride bicycles with my wife and friends.

An IndieWeb Webring 🕸💍