47

I would like to know which are the standard commands available in every Linux system.

For example if you get a debian/ubuntu/redhat/suse/arch/slackware etc, you will always find there commands like:

cd, mkdir, ls, echo, grep, sed, awk, ping etc.

I know that some of the mentioned commands are shell-builtin but others are not but they are still always there (based on my knowledge and experience so far).

On the other hand commands like gawk, parted, traceroute and other quite famous commands are not installed by default in different Linux distributions.

I made different web searches but I haven't found a straight forward answer to this.

The purpose is that I would like to create a shell script and it should make some sanity checks if the commands used in the script are available in the system. If not, it should prompt the user to install the needed binaries.

5
  • 6
    Just a hint: "it should make some sanity checks if the commands used in the script are available in the system" sounds very much like Autoconf.
    – sr_
    Commented Apr 22, 2012 at 15:00
  • Definitely a case for auto-config...or perhaps its more scientific cousin, promise theory.
    – Wildcard
    Commented Apr 3, 2016 at 6:13
  • @Wildcard, I believe that any configuration management system would be an overkill for such a case, unless you want continuous sanity checks and self-healing of the system even after the initial installation. Commented Apr 4, 2016 at 17:43
  • @VangelisTasoulas, I don't think so. In a single-user setup such as a home computer, why would you need to script it? Config management would be overkill—but so would a scripted check vs. manual. In a scenario where you have multiple boxes upon which you want to ensure consistency, scripting wouldn't be overkill—but neither would config management. Or are you a software developer just wanting to run sanity checks during package installation for your product? It depends on your scenario, yes, but if you want to manage your configuration, a configuration management tool isn't overkill. ;)
    – Wildcard
    Commented Apr 4, 2016 at 18:15
  • 1
    @Wildcard, When I wrote this question I was thinking about the latter: Just want to run sanity checks during the installation in a single machine, in order to ensure that the software will be running properly. Of course, if you want to manage multiple servers and handle distributed deployments etc, then I agree that configuration management is the way to go in the long run. Commented Apr 4, 2016 at 21:19

3 Answers 3

51

Unfortunately there is no guarantee of anything being available.

However, most systems will have GNU coreutils. That alone provides about 105 commands. You can probably rely on those unless it's an embedded system, which might use BusyBox instead.

You can probably also rely on bash, cron, GNU findutils, GNU grep, gzip, iproute2, iputils, man-db, module-init-tools, net-tools, passwd (passwd or shadow), procps, tar, and util-linux.

Note that some programs might have some differences between distributions. For example /usr/bin/awk might be gawk or mawk. /bin/sh might be dash or bash in POSIX mode. On some older systems, /usr/bin/host does not have the same syntax as the BIND version, so it might be better to use dig.

If you're looking for some standards, the Linux Standard Base defines some commonly found programs, but not all distributions claim to conform to the standard, and some only do so if you install an optional LSB compatibility package. As an example of this, some systems I've seen don't come with lsb_release in a default install.

As well as this, the list of commands standardized by POSIX could be helpful.

Another approach to your problem is to package your script using each distribution's packaging tools (e.g. RPM for Red Hat, DEB for Debian, etc.) and declare a dependency on any other programs or packages you need. It's a bit of work, but it means users will see a friendlier error message, telling them not just what's missing, but what packages they need to install.

More info:

3
  • The package-and-add-dependencies-idea is great, beats diving into Autoconf hands down :)
    – sr_
    Commented Apr 22, 2012 at 16:14
  • 2
    great answer, i agree with everything. i'd add an extra caution step: take into account the extra specific options of the particular version of the command you're using...they might not work on all versions (this has happened in a project i worked in). Commented Apr 23, 2012 at 12:21
  • 1
    I don't suppose there's a plaintext file with a list of these commands anywhere? pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html can relatively be easily be converted to that but is still missing a bunch of stuff. Commented Dec 17, 2018 at 1:39
8

On non-embedded Linux systems, you can generally count on most GNU utilities:

plus the util-linux suite and the procps suite. Note that /bin/sh is not always bash, it can be a shell with less features such as one of the multiple forks of ash.

The Linux Standard Base defines a set of common utilities with features that are expected on all conforming systems. You can also expect most of the utilities specified by POSIX. A notable exception is pax, which is not part of the default installation of many distributions.

If you want to keep things simple, request the installation of a lsb_release package. Many distributions have such a package that pulls in all the dependencies required by the LSB.

On an embedded system, all bets are off. Embedded Linux systems usually run BusyBox, but a lot of utilities and features are optional, so there's very little you can be sure of getting.

1
  • "If you want to keep things simple, request the installation of a lsb_release package." In a similar vein, there is the posix meta-package package on Arch Linux: archlinux.org/packages/community/any/posix
    – kelvin
    Commented May 18, 2021 at 13:23
6

There is a set of commands most if not all Linux distributions, and for that matter, also Unix distributions will provide. These are the mandatory commands specified by the POSIX standard.

Most of the commands you cite (cd, mkdir, ls, echo, grep, sed, awk, etc.) are of it. The exception being ping as WhiteWinterWolf rightly commented.

3
  • 1
    Actually ping is not part of POSIX... Commented Mar 1, 2017 at 16:20
  • The POSIX homepage states that they focus on ensuring "application portability at the source code level", ie. as per my understanding they are interested in system API, system (including shell) behavior and commands which may be used to configure, compile and install an application and handle its source code. Commented Mar 2, 2017 at 13:30
  • They don't care about networking utilities ("System configuration and resource availability" are explicitely out-of-scope), so ubiquitous commands such as ping, ifconfig, telnet, etc. are not part of this standard (nor any other one AFAIK, they just aim compatibility with "historical implementations" on a best-effort basis). Commented Mar 2, 2017 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .