When you are using the command line on Windows, Linux, or Mac, many of the commands that you run are actually little programs exist on your computer in a place that is known to contain little programs. These programs are part of the core of an operating system.
These programs are referred to as either binary files, or simply binaries, and they are nothing more than files stored on your computer. They are easy to run because you can simply type their name at the command line, and they run.
System binaries are the binaries that ship with an operating system. User binaries are binaries that you install on your computer, or that you write yourself.
Example System Binaries
Programs that ship with your operating system, and can be usually ran from any directory on your system are called system binaries. System binaries are stored at different places on Windows and Linux.
System Binaries on Windows
On Windows, system binaries are stored in the
C:\Windows\System32 directory. This is a directory that is part of the core of Windows, and it is always available on your computer. You can run any of the binaries in this directory by typing their name at the command line.
On Windows, commands such as:
Are all binary files that exist on your computer thanks to your operating system. The files that these commands run are actually 'ping.exe', 'net.exe', and 'reg.exe'. Windows knows to strip off the .exe part and just run the command that you typed in.
The .exe file extension on Windows denotes an executable file. Linux and Mac do not use this convention.
In the case of these binaries, they happen to exist in
c:\windows\system32, which is part of your system path, which we'll talk about more below. Since these files exist in your path, you can simply type the command 'ping' at the command prompt and Windows finds the binary file 'ping.exe' and runs it.
System Binaries on Linux
On Linux systems, system binaries are stored in the
/bin directory. This is a directory that is part of the core of Linux, and it is always available on your computer. You can run any of the binaries in this directory by typing their name at the command line.
Note: On many Linux distributions such as Debian and Ubuntu, the
/bindirectory is a symbolic link to the
/usr/bindirectory. This is a common convention on Linux, and it is not important to understand the difference between the two directories. Just know that the binaries that you want to run are in the '/bin' directory.
On Linux and Mac, commands such as:
Are actually binary files that usually exist in
/bin/. Since they exist in your path, then you can simply type the command
ping at the command prompt and the operating system runs it.
Notice that Linux and Mac do not name their binary files with a .exe extension like Windows does. Instead, Linux and Mac rely on the execute bit being set in the file system to mark a file as executable.
What is the System Path Used For
How does your system know which binary files you want to run? That's what the system path is for.
The reason that you can run these commands, or binaries, is because they exist in what is called your system path. The system path is a list of directories on your computer that the operating system knows to search for binaries in.
On Windows, your system path includes directories such as:
On Linux and Mac your system path includes:
If an executable file exists in your system path, then you can run it by typing its name at the command line. If it does not exist in your system path, then you must type the full path to the file in order to run it.
View Your Current System Path
To view your current path on Windows, there are 2 different commands depending on if you are running the traditional command prompt or the new PowerShell command prompt.
Windows Command Prompt (cmd.exe):
Windows PowerShell or Terminal:
On Linux and Mac you can view your current path by typing:
Not all commands that you run are actually binary files. Some commands are actually built into the shell itself. These commands are called internal commands. These commands are called 'internal commands' because they are internal to the command interpreter of your operating system. They are not binaries that you download and run. Example internal commands are:
You will not find binaries for these commands because they are built into the operating system. You can run them from any directory on your computer.
Creating Your Own Binaries
You can create your own binaries on Windows, Linux, and Mac. You can create your own binaries in C, C++, C#, Java, Python, Ruby, or any other language that you want. Once you have created your binary, you can place it in any directory that is in your system path, and you can run it from any directory on your computer.
You may want to consider making a directory on your computer to store your own binaries. For example, on Windows you can create a directory called 'c:\bin', and then add that directory to your system path. Then you can place your binaries in that directory run them from any directory on your computer.