The other day, @WilsonPhillips mentioned an alias he uses for lsblk
which was super helpful. It got me thinking about my own aliases.
So no one feels left out
For new users, aliases are easy to add, so long as you properly format them and know where to put them! You just have to edit the .bashrc file in your user’s home folder!
Using Dolphin
You can do “using” dolphin. Enable your ability to see hidden files and folders by pressing ctrl+h
or by selecting view in the titlebar menu, and selecting “Show Hidden Files” then you’ll see a bunch of files and folders that start with .
indicating that they are hidden.
Before we edit the .bashrc file, let’s copy it to make a backup, just in case we make a mistake and take something out or something! Copy the file (by right-clicking it, or pressing crtl+c
, then pasting it by right clicing in our home folder and pressing paste, or pressing crtl+v
, when it asks us about renaming, just add .bak
to the end of the file and you’ll have made yourself a backup copy of the file.
At any rate, find the file called .bashrc and open it to edit.
In the Terminal
For those who like to use the terminal, immediately after opening the terminal (Konsole
in KDE), you will be in your home directory. If you aren’t, just type:
cd
And you will find yourself at home! No place like it. Let’s make a copy of .bashrc by running the following in the terminal:
cp .bashrc .bashrc.bak
Now you’ve made a backup copy–juuuuuust in case. Anyway, type the following, or use your editor of choice:
nano .bashrc
Any aliases you add can be put at the bottom of the file (unless you like to organize your .bashrc file! lol). I’ll give you some of my favorite aliases in a moment, but just remember to save your edits to .bashrc before closing. In nano, just press crtl+s
to save and then crtl+x
to exit.
A quick note
After saving .bashrc in the terminal, new aliases will not be immediately active because BASH needs to be reinitialized (reload the basrc file) to see your new aliases. You can do this by running:
exec bash
or by opening a new terminal. If you edited and saved via the dolphin method discussed earlier, any new terminal you open will read your aliases right away.
Troubleshooting
You may find, however, that your aliases were incorrectly formatted and may cause your terminal not to open. No worries, just remove that alias. A good way to test an alias is by using it temporarily. You can do this by just run the following into an open terminal:
alias hello='echo "well, hello to you!"'
Now type hello and the response will follow:
If you’ve entered an improrperly formatted alias, the terminal will say so. This method of testing aliases before putting them into the .bashrc file saves us from having to restore a backup or editing it to remove the offending alias causing BASH to hiccup, but it’s one more step that may save us from walking around the block. Anyway, so much for exposition!
Some of my aliases
Here are some of my favorite aliases:
alias ls=‘LC_COLLATE=C ls -h --group-directories-first --color=auto’
alias dnf-history=“rpm -qa --last | less”
Explanation of Aliasing
The alias
at the head of the line tells BASH that these are aliases for commands so whenver I type a word it will run what is on the “other side” of the equal sign.
Now, ls
modifies the list command to run as what follows the equal sign: “LC_COLLATE=C ls -h --group-directories-first --color=auto” which, for me, makes ls much more readable.
My dnf-history
command helps me to see what changes have been made recently, which helps me troubleshoot a problem if a recent system change can be narrowed down to a recently installed package. Some folks would never use that, but I find it fun.
At any rate, what are some of your favorite aliases?