Favorite Aliases

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?

4 Likes

Obvious ones
update=‘sudo dnf clean all ; dnf clean all ; dnf repo-list’
upgrade=‘sudo dnf --allowerasing dsync’
for if im feeling really lazy
u=‘update && upgrade’
also use
s=dnf search
r=sudo dnf remove
looking forward to some new and more original ideas
@P_J greate idea for a post by the way.

3 Likes

On a dev machine it is nice to have a responsive system:

for n in rpmbuild mock make cmake ninja rpkg fedpkg tar rake
  do alias $n="nice $n"
done

cd into the top-level git directory:

alias c='x=`git rev-parse --show-toplevel 2> /dev/null`; if [[ "$x" != "" ]]; then cd $x; fi'

Random aliases:

alias o='xdg-open'
alias whatismyping='ping -n 8.8.8.8 | cut -d= -f4'
alias max='brightnessctl set 100%'
alias lshost='doctl compute droplet list'
alias a='atom .'

Still plan to switch from the atom editor sometime…

3 Likes

I have some of my aliases disabled due to lack of packages. Here are the few that work right now.

alias dup='sudo dnf clean all ; dnf clean all ; sudo dnf distro-sync --refresh --allowerasing ; flatpak update' # Distro upgrade
alias din="sudo dnf install " # DNF install of packages
alias drm="sudo dnf remove" # DNF remove package
alias reboot='systemctl reboot' # allows reboot from the command line
alias off='systemctl poweroff' # allows power down from the command line
alias lsblk='lsblk -o path,label,uuid,fstype'

By the way. All of my aliases are in ~/.bash_alias and they are called from /.bashrc with the following command. I do the same with my prompts.

source ~/.bash_alias
2 Likes

@richp :laughing: yep! exactly, I have an alias for upgrading as well, thanks to a few additions from others:

upgrade='sudo dnf clean all;sudo dnf distro-sync --refresh --allowerasing; flatpak update -y'

@jonny Wow, nice! as a non-dev, I just stare at most of your aliases, lol, but that is awesome!
@WilsonPhillips what a good suggestion. I had forgotten about the include for a separate file for aliases. It would make it easy to migrate systems at set up VMs! I’m going to have to implement that.

1 Like

@P_J Nice idea and useful topic :+1:

1 Like

Funny I always used source ~/.bashrc instead.

@rugyada Thanks! I’m hoping for some new ideas, :smiley:
@nesh Lol, gotta love Linux, there’s always more than one day to do something! I feel like I win because my command is shorter, lol :stuck_out_tongue_closed_eyes: