sysadmin
dnf tips and tricks
dnf tips and tricks
- dnf tips and tricks
- Listing Packages Installed
- Listing Packages available
- Checking Package Information
- Checking for Security Updates
- Cleaning DNF Cache
- Searching DNF history
- Searching a Package
- List active repositories
- Enable/Disable a repository
- Update while excluding a package
- Adding a repository manually
- Adding Repositories with DNF config-manager
- Removing Repositories
Listing Packages Installed
sudo dnf list installed
Listing Packages available
sudo dnf list available
Checking Package Information
To check detailed information about a package, use the dnf info command:
# sudo dnf info nano
Installed Packages
Name : nano
Version : 5.6.1
Release : 5.el9
Architecture : x86_64
Size : 2.7 M
Source : nano-5.6.1-5.el9.src.rpm
Repository : @System
From repo : anaconda
Summary : A small text editor
URL : https://www.nano-editor.org
License : GPLv3+
Description : GNU nano is a small and friendly text editor.
Checking for Security Updates
Use the ‘–security’ flag with the updateinfo command to see if there are any security updates available.
sudo dnf updateinfo --security
Cleaning DNF Cache
DNF keeps a cache of the package metadata to speed up operations. However, it can sometimes become outdated. You can clean the cache using dnf clean:
sudo dnf clean all
Searching DNF history
DNF provides the history command as a means to monitor the activities executed by DNF. This can assist in the troubleshooting process should any issues arise.
sudo dnf history
Searching a Package
To search for a package, use the dnf search command. For example, to search for packages related to Python:
sudo dnf search python
List active repositories
# dnf repolist
Updating Subscription Management repositories.
repo id repo name
code Visual StudioCode
codeready-builder-for-rhel-9-x86_64-rpms Red Hat CodeReady Linux Builder for RHEL 9 x86_64 (RPMs)
copr:copr.fedorainfracloud.org:cboxdoerfer:fsearch Copr repo for fsearch owned by cboxdoerfer
epel Extra Packages for Enterprise Linux 9 - x86_64
rhel-9-for-x86_64-appstream-rpms Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPMs)
rhel-9-for-x86_64-baseos-rpms Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs)
rhel-9-for-x86_64-supplementary-rpms Red Hat Enterprise Linux 9 for x86_64 - Supplementary (RPMs)
Enable/Disable a repository
Enable a repository
# dnf config-manager --set-enabled <repo>
Disable a repository
# dnf config-manager --set-disabled <repo>
Update while excluding a package
# dnf update -y --exclude "code"
Adding a repository manually
# cat /ec/yum.repos.d/pel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$releasever
Description of each line
`epel`: Is the repository ID.
`name`: The human-readable name of the repository.
`baseurl`: The URL for the repository.
`enabled=1`: This enables the repository. To disable, change this to 0.
`gpgcheck=1`: This enables GPG signature checking. To disable, change this to 0.
`gpgkey`: The URL for the GPG key that should be used to sign the packages.
Adding Repositories with DNF config-manager
Before proceeding, ensure the dnf-plugins-core package is installed in your Fedora system. If not, you can install it using:
sudo dnf install dnf-plugins-core
Adding Repositories with DNF config-manager:
Let’s say you want to add a repository from the URL http://www.example.com/myrepo/.
With dnf config-manager, it’s as simple as this:
sudo dnf config-manager --add-repo http://www.example.com/myrepo/
The above command will create a .repo file under /etc/yum.repos.d/ for you.
Removing Repositories
sudo rm /etc/yum.repos.d/MyRepo.repo
Resetting file permission with rpm
Did you know that you can reset file permission to what they were when you installed the package. This may become helpful if somebody made a mistake and change the permission on a number of files (This never happen right).
Force user to change password
User is calling and say that he forgot is password. So you need to change his password and for security reason you want to force him to change it upon his first login. The command “chage -d 0” (change aging) will force user to change his password upon first login.
General
Doing more with less
We usually use the “less” command to browse the content of a text file. We use the [Page-Up], [Page-Down], [Down-Arrow], [Up-Arrow] keys to move within the file, but did you know that you can do more with the less command ?
Network
Identify physical network port name
The ‘ethtool’ is a command line utility used to query and control network device driver and hardware settings, particularly for wired Ethernet devices. In our example, we will use it to flash the light on the back of a card, this will be useful to identify the device name that belong to what port on the back of you Linux computer.
Scripting
Making Date Calculation
You’re doing a script and you need to know what was the date 35 days ago or what will the date be in 21 days. This is where the “date” command can help you doing that kind of calculation. In this little article we will present some examples to help us making some data calculation. I would like to point out, that all of these date calculation take in consideration the leap year.
general
Linux Administration Books for Free
A short post to list some free books for Linux users and administrators, take a look you might find one that you would like to have.
tips_and_tricks
Search and replace multiple files
At one point, you may be facing a situation where you would want to do an in place replacement of one string by another in multiple files. In this article, we will demonstrate a couple a way to do it, one solution using ‘perl’ and a second using ‘sed’.