Having some experience with Linux, you probably know that you can't just share a command or a utility between systems. The reason that you can't simply copy an executable from one system to another is because of dependencies, such as libraries and other supporting packages. Some utilities certainly can be copied but this isn't universally so. If you've forgotten which package you installed that included the
nslookup command, for example, you need a way to find it.
Furthermore, once you find the package that a command belongs to, you might want to find out from which repository you installed the package. The basic repositories of AppStream, BaseOS, and Extras contain a lot, but certainly not all of the packages you might need or encounter. In this article, I explore some methods of querying the system to find related repositories, packages, and commands.
- Packages contain commands, utilities, and libraries
- Packages have dependencies
- Repositories contain, store, and provide packages
Classifying the file type
Is the utility you're using a script, plain text, or a command? Is it compiled? What is the file's location? You might want some basic information about the utility. The
which command locates a file if it's in your path. You will need to locate a file before you can further identify it.
$ which mtr /usr/sbin/mtr
To display file type information, the
file command is indispensable.
$ file mtr mtr: cannot open `mtr' (No such file or directory) $ file /usr/sbin/mtr /usr/sbin/mtr: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=d34479cefafe7299b65d8375769c63978c6c453f, stripped, too many notes (256)
The first attempt failed because the
file command doesn't know the location of the
mtr command. After the full path is given to
file, the information is displayed.
Here is an example of an executable file that is not compiled.
$ file /usr/sbin/ifcfg /usr/sbin/ifcfg: POSIX shell script, ASCII text executable
As you can see, the
file command is an important one to know and one which you're sure to use throughout your career.
[ Readers also liked: Linux package management with YUM and RPM ]
Finding the package
nslookup command is one that you use frequently but it isn't installed on any of the systems at your new job. You want to install it but you can't remember which package contains it and attempting to install it as
# dnf -y install nslookup Last metadata expiration check: 2:44:51 ago on Tue 10 Nov 2020 03:27:27 PM CST. No match for argument: nslookup Error: Unable to find a match: nslookup
To find the package that contains
nslookup, you can perform a "reverse" lookup using the
# rpm -qf nslookup error: file /root/nslookup: No such file or directory
What's wrong here? The
rpm command can't find
nslookup but it's installed because you've used it. Wait. Look at the path:
/root/nslookup. There's no
nslookup command in your current (root's home) directory. Locate
nslookup using the
which command and then issue the
# which nslookup /usr/bin/nslookup # rpm -qf /usr/bin/nslookup bind-utils-9.11.13-6.el8_2.1.x86_64
You see that
nslookup is part of the
bind-utils package. Now you can copy it to your other systems and use it as you normally would.
# nslookup google.com /opt/nslookup: error while loading shared libraries: libdns.so.1107: cannot open shared object file: No such file or directory
The error tells you that the
nslookup command has dependencies that haven't been met on the new system you've copied it to. The solution is to install it individually onto each system using DNF/YUM.
Revealing package dependencies
You really like the
nslookup command, and you'd like to have it available on all of your systems. You realize after a failed attempt that you can't simply copy it to another system and expect it to work. After much research, you discover that the
nslookup command has several dependencies that must be met. What are those dependencies?
# dnf deplist nslookup Last metadata expiration check: 3:00:24 ago on Tue 10 Nov 2020 03:27:27 PM CST.
Does this mean there are no dependencies for
nslookup? No. It means that you attempted to find dependencies for a command rather than for a package.
# dnf deplist bind-utils Last metadata expiration check: 0:00:14 ago on Tue 10 Nov 2020 06:29:37 PM CST. package: bind-utils-32:9.11.13-6.el8_2.1.x86_64 dependency: /usr/libexec/platform-python provider: platform-python-3.6.8-23.el8.i686 provider: platform-python-3.6.8-23.el8.x86_64 dependency: bind-libs(x86-64) = 32:9.11.13-6.el8_2.1 provider: bind-libs-32:9.11.13-6.el8_2.1.x86_64 *** longer list of dependencies *** dependency: rtld(GNU_HASH) provider: glibc-2.28-101.el8.i686 provider: glibc-2.28-101.el8.x86_64
Remember that packages have dependencies. Listing dependencies can be valuable if you want to satisfy them manually or if you think that new dependencies might interfere with or be incompatible with packages and dependencies already installed on your system.
Identifying the repository
You saw a fellow sysadmin using the hardware information tool (
hwinfo) command on her system. You try the command on your system but you receive a "command not found" error. You then attempt to install it.
# dnf -y install hwinfo Last metadata expiration check: 0:09:34 ago on Tue 10 Nov 2020 06:42:15 PM CST. No match for argument: hwinfo Error: Unable to find a match: hwinfo
You ask your coworker to tell you where she got the
hwinfo package. She performs the following query to find its source.
# dnf list hwinfo Last metadata expiration check: 0:11:17 ago on Tue 10 Nov 2020 06:42:15 PM CST. Installed Packages hwinfo.x86_64 21.47-9.el8 @epel
You note that the source appears to be a repository identified as
epel. You further ask her to tell you how to set up the
epel repository. She remembers that epel is actually an installable RPM package but doesn't remember its full name. She performs the following query to identify it.
# rpm -qa |grep epel epel-release-8-8.el8.noarch
Now you can install the
epel-release package and then install the
epel-release repository is the Extra Packages for Enterprise Linux repository configuration and is the first thing I install on any new system I encounter that doesn't have it.
[ Free download: Advanced Linux commands cheat sheet. ]
Linux provides its administrators with a lot of handy utilities and commands to find information about the system and its components. You need to add these commands and utilities to your sysadmin toolbox. As you can see from this article, you don't need to know a command's every obscure option to get what you need. Use
man pages for those.