DEV Community

Eric F 🇺🇦
Eric F 🇺🇦

Posted on

One of the real gems with the DNF package manager: aliases

One of the things i really like about the DNF package manager, is th built-in “alias” system. It's awesome. Because you know how it is, when you have package manager, and a lot of commands to keep track of - we tend to setup a bunch of aliases in our .bash_files. Like I have a few different ones I then source into my .bashrc depending on what system I've setup. So, on an Arch system, I have an pacman-file with only aliases for different pacman commands. With Debian I haven a file called ”apt”.
Then I can source them in .bashrc like:

for f in aliases functions git pacman; do
    [ -f ~/.bash.d/${f} ] && . ~/.bash.d/${f};
done
Enter fullscreen mode Exit fullscreen mode

 

With DNF, there is no need for that. Well, except maybe 1. I do have an alias with: alias sdnf='sudo dnf '.

But, it's really great, and you can keep your .bash_files cleaner - and, when exploring what you can do and setup with the alias system - you'll learn a lot about your package manager.


So, DNF have (by default) already a bunch of pre-defined aliases. Like: in (install), rm (remove), ls (list), se (search), up (upgrade) + more. If you read the man dnf, you can see all the ones that are already made.

And it's really easy to add them your self. Here's how you do it:

# Basic syntax
$ sudo dnf alias add <alias>=<command/replacement>

# List your added aliases
$ dnf alias list
Enter fullscreen mode Exit fullscreen mode

Examples

Here are a some examples, to show a few.

In Apt you have “show”, and in DNF it is “info”. So, after using a Debian system during the day, and then later back at home - I sometimes tend to mix them up. Easy to fix:

$ sudo dnf alias add show=info
Enter fullscreen mode Exit fullscreen mode

There's already “up” for upgrade, so I've added:

$ sudo dnf alias add chup=check-update
Enter fullscreen mode Exit fullscreen mode

There's already “rm” for remove, so I've added:

$ sudo dnf alias add aurm=autoremove
Enter fullscreen mode Exit fullscreen mode

And here's an example of how you list them:

$ dnf alias list
Alias show='info'
Alias aurm='autoremove'
Alias chup='check-update'
Alias h='help'
Alias i='info'
Alias yin='in -y'
Alias yup='up -y'
Enter fullscreen mode Exit fullscreen mode

There is one thing to be aware of though… You can read more about it in the manual, but when using an already defined command/alias - you need to “\backslash” it to prevent an infinite loop.

Maybe not a good example, but like:

$ sudo dnf alias add list='list installed'
Enter fullscreen mode Exit fullscreen mode

That one needs a backslash, like:

$ sudo dnf alias add list='\list installed'
Enter fullscreen mode Exit fullscreen mode

Well, it's easy, fun, and really useful, and less clutter in you .bash_files. Plus, you'll learn more about DNF when exploring all its options.

 

// Happy hacking… ⌨️ 👍

· Eric

Top comments (0)