How to Execute Programs From Anywhere in Linux?

Linux is a widely used open-source operating system that offers users the flexibility to execute programs from any location on the system. Unlike other operating systems, Linux does not have fixed program directories, enabling users to access programs from anywhere. This feature is advantageous for users who require a particular program to run from multiple locations. To execute programs from anywhere in Linux, users need to set the PATH environment variable, which contains the locations where Linux searches for executable files. The directories that contain the programs in Linux include /usr/bin, /usr/local/bin, and /sbin. The /usr/bin directory contains most of the user applications, while the /usr/local/bin directory contains locally installed programs. The /sbin directory contains essential system administration programs, and only the root user can access it. Understanding these directories and how to execute programs from anywhere in Linux is crucial for an efficient and productive Linux user.

About /bin or /sbin in Linux

The majority of Linux programmes are found in either /bin or /sbin. As a result, they can be run from anywhere in our system.

We might place our programme in one of these directories. While this answers our problem, it is not a good idea because /bin and /sbin are reserved directories

/bin contains all basic Linux commands such as cp, ls, and mkdir. /sbin contains system administrator commands such as fsck and dmesg.

Provided our software is not required by the operating system or an administrator command, it has no place in these areas. We don't want to fool around in these directories either. We might inadvertently break anything.

The /usr Directory in Linux

The bulk of user apps and utilities are located under the /usr directory. It is distinct from the root directory and can be mounted on a different disc or partition. The /usr directory is divided into subdirectories like as /usr/bin, /usr/sbin, and /usr/local.

The directory /usr/bin includes user-level binaries that are not required for the system to start or function. These programmes are typically installed as part of the initial installation of the operating system or as packages later on. ls, cp, mv, rm, and other often used programmes can be found in this directory.

System binaries that are necessary for the system to function properly can be found in the /usr/sbin directory. These apps are not meant for regular users, but rather for system administrators. Mount, fsck, fdisk, and other often used applications can be found in this directory.

The /usr/local directory is where software is installed locally. System administrators frequently utilise this directory to install bespoke software that is not included in the official package repositories. Local binaries are found in the /usr/local/bin directory, while local system binaries are found in the /usr/local/sbin directory.

The /opt Directory in Linux

The /opt directory, which stands for optional or supplementary software, is a regularly used directory on Linux systems. Vendors or developers generally utilise this directory to install optional software that is not included in the official package repositories.

The /opt directory is for software that is not included in the operating system's default installation or vendor-supplied packages. It's a separate area where we can install software that isn't provided by the distribution's package manager but has to be available system-wide.

The vendor or developer is responsible for organising the installed files in the /opt directory. The software can be placed in subdirectories, with the vendor deciding on the optimal naming convention for the product. Software could, for example, be installed in a directory structure such as /opt/myapp/bin, /opt/myapp/lib, or /opt/myapp/doc.

The /opt directory is helpful for software that requires special installation processes, is not open-source, or is only available in binary form. Oracle Database, Google Chrome, and Adobe Acrobat Reader are examples of software that is routinely installed under /opt.

While the /opt directory is not a required component of the Filesystem Hierarchy Standard (FHS), which defines the structure of a Linux file system, it is commonly used by most Linux distributions.

Installing software in the /opt directory has the advantage of keeping it separate from the system's default directories, such as /usr and /bin. This ensures that the software will not overwrite or clash with any system files or programmes. Also, the package manager does not automatically update the applications installed under /opt, which can be an advantage or disadvantage depending on our needs.

The PATH Variable in Linux

The shell looks in the folders listed in the PATH environment variable for executable files. When a user types a command into the terminal, the shell searches each directory mentioned in the PATH variable for the executable file. If the file is discovered, it is run. If the file cannot be located, the shell generates an error.

Usually, PATH is specified in the user’s bashrc or.zshrc shell configuration file. By default, the /bin, /usr/bin, and /usr/local/bin folders are included in the PATH variable. System administrators can add additional directories to the PATH variable as needed.

To add a directory to the PATH variable, use the export command. To add the directory /opt/myprogram/bin to the PATH variable, for example, type −

export PATH=$PATH:/opt/myprogram/bin

This command expands the current value of the PATH variable to include the location /opt/myprogram/bin.


Linux allows us to execute programs from anywhere on the system, making it a flexible and customizable operating system. Understanding the directories that contain programs and how the PATH environment variable works is essential for using Linux effectively. By knowing how to execute programs from anywhere, users can take full advantage of Linux's flexibility and power.

Updated on: 08-May-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started