Which are the standard commands available in every Linux based distribution?

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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:

Method 2

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.

Method 3

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x