Adding a directory to the PATH variable

By default, there are a lot of different directories which are present in this variable, we can also add our own directory into the PATH variable which will enable us to run our script or command from anywhere in the system. This definitely saves a lot of time and effort. There are two ways in which we can add to PATH:

  1. By appending (This adds our path at the end of the PATH variable)
  2. By prepending (This adds our path at the beginning of the PATH variable)

Now we have to attach the /home/mukul/bin to the path, use the below command:

export PATH = $PATH: /home/mukul/bin (appending)
export PATH =  /home/mukul/bin :$PATH (prepending)

You can see that our path has been added to the path variable.

Now we can run our “Sample.sh” script from anywhere and that too without any path or “./” mentions.

Running script

Note: Make sure to give permission to your file, or else it will give an error.

chmod +x Sample.sh

You have misspelled the command:

We all make mistakes and that is a natural thing, this error can also arise when we type the command incorrectly.

For example, If we type PQD instead of PWD we will get this error.

Error

So, these were the four ways in which you can get rid of the Bash: Command Not Found Error in Linux.

How to fix Bash: Command Not Found Error in Linux

The “command not found” error is a frequently encountered issue in Linux systems. This error occurs when the system is unable to locate the file specified in the path variable.

Similar Reads

What is a path variable?

In Linux, the path variable informs the system about specific locations to search for files or commands. Typically, the path variable includes paths such as /usr/local/sbin, /usr/bin, /usr/local/bin, and more. Fortunately, we don’t need to specify the path variable each time, as it is pre-configured to search for programs in all directories....

Different ways to fix this error:

Installing the package which is not present:...

Adding a directory to the PATH variable

By default, there are a lot of different directories which are present in this variable, we can also add our own directory into the PATH variable which will enable us to run our script or command from anywhere in the system. This definitely saves a lot of time and effort. There are two ways in which we can add to PATH:...

Conclusion

This article explores the common issue of encountering the “command not found” error in Linux systems. This error often occurs when the system cannot find the specified file in the path variable. However, there are effective solutions to overcome this error, including installing missing packages, explicitly specifying paths, modifying the path variable, and ensuring accurate command spelling. By understanding and implementing these solutions, users can enhance command execution efficiency and enjoy a more seamless Linux experience....