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.

On a side note, one of my aliases is fairly new and was created after hearing about some listener feedback to the Late Night Linux episode 181. The alias is “warp” and it plays white noise that is supposed to sound similar to the warp engines on Star Trek’s USS Enterprise.

alias warp='play -n -c1 synth whitenoise band -n 100 20 band -n 50 20 gain +25 fade h 1 864000 1'
60 seconds of warp engine white noise.

When used with my Bose QC 45 noise cancelling headphones, I find it strangely comforting and I think it helps me to get into the zone.