Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
4  
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_ Apr 22 '12 at 15:00
add comment

3 Answers

up vote 21 down vote accepted

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, 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:

share|improve this answer
    
Thanks, these links looks quite useful –  Vangelis Tasoulas Apr 22 '12 at 15:22
    
The package-and-add-dependencies-idea is great, beats diving into Autoconf hands down :) –  sr_ Apr 22 '12 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). –  JoséNunoFerreira Apr 23 '12 at 12:21
add comment

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.

The commands you cite (cd, mkdir, ls, echo, grep, sed, awk, ping etc.) are all part of it.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.