Command vs program?
In simple terms, a command is an instruction (or a set of instructions) to be carried out by a computer.
Stand-alone commands
Fundamental Unix utilities such as ls
, ln
, etc. are (usually) written in C and compiled to be stand-alone executable programs that don’t require an interpreter to be executed; they usually require certain library files to be installed on the system but that’s an answer for another question.
Scripts
A script is a collection of commands and in fact, scripts themselves are considered to be a command.
A Perl script is a sequence of Perl statements and requires a perl
executable (stand-alone and compiled) program to interpret the Perl statements.
Sometimes large and complex interpretative scripts (in languages such as Perl, Python and Ruby) are also referred to as interpreted programs while the term script is reserved for shorter and simpler scripts.
A shell script is a sequence of other commands (any type of command) and it requires a Unix shell such as Bash to interpret the script. From the Bash man page:
Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.
Shell Built-ins
Shells usually have built-in commands which are neither stand-alone programs nor scripts. Instead, they are part of the shell itself and run directly by the shell. cd
is an example of such a built-in command.
Some times there are commands which exist as shell built-ins and as
stand-alone commands at the same time, e.g., the echo
command.
$ type -a echo
echo is a shell builtin
echo is /usr/bin/echo
echo
on its own executes the shell built-in while the stand-alone command can be executed by providing its full path.
Run built-in version of echo:
$ echo --version
--version
Run stand-alone echo
program:
$ /usr/bin/echo --version
echo (GNU coreutils) 8.23
Packaged by Cygwin (8.23-4)
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Note: The above specifics refer to a Unix environment but the same principles apply to a Windows environment.
A built in command is part of the shell. A program is executed by the shell.
Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command (see Simple Commands), the shell executes the command directly, without invoking another program. Builtin commands are necessary to implement functionality impossible or inconvenient to obtain with separate utilities.
http://www.gnu.org/software/bash/manual/bashref.html#Shell-Builtin-Commands
Command just means a way to tell an application or system to do something.
An application will typically accept many different commands, either from the GUI, from stdin
, but other methods are possible, e.g. a UNIX socket or named pipe, some sort of web API, an RPC connection, or some other custom protocol.
An application that does only one thing, then exits, typically without a GUI, can also be called a command, because you can really only "give" this application one meaningful "command." This is how small programs like ls
and such work and why they are called commands.
But you wouldn't call Photoshop a command, but you'd certainly issue commands within it via the GUI.
However, the term can mean different things to different people. In your example, command is being used to describe an executable that is run directly, versus a file that requires a script interpreter to work. The distinction can be important because when you are running a Perl script, /usr/bin/perl
is the binary that is actually running (so if you want to kill a long running Perl script, that's what you have to look for in ps
). However, most shells have "built-in" commands that are commands to the shell itself and don't cause an external executable to run. For example, cd
is handled by bash
itself and it doesn't call /sbin/cd
or similar.