Software & AppsOperating SystemLinux

Fixing “sudo: ./ command not found” Error in Bash Scripts

Ubuntu 9

In the world of Linux, Bash scripts are a powerful tool for automating tasks. However, sometimes you may encounter errors when trying to execute these scripts. One such error is “sudo: ./ command not found”. This article will provide a detailed guide on how to resolve this error.

Understanding the Error

The error “sudo: ./ command not found” typically occurs when the shell is unable to locate and execute the script file. There could be several reasons for this, including incorrect file permissions, an incorrect or missing shebang line, incorrect line endings, or an incorrect file location.

Fixing the Error

Check File Permissions

The first thing to check is whether the script file has the execute permission. In Linux, you can use the chmod command to change the permissions of a file. The +x parameter adds the execute permission to the file.

chmod +x

This command will make the file executable for the current user. If you’re still encountering the error, you may need to use sudo to grant the necessary permissions.

sudo chmod +x

Note: Using chmod 777 is not recommended as it gives all permissions to everyone, which can pose a security risk.

Check the Shebang Line

The shebang line is the first line in a script file and it specifies the interpreter that should be used to execute the script. For a bash script, the shebang line should be #!/bin/bash.

If the shebang line is missing or incorrect, you can specify the interpreter explicitly while running the script.

sudo bash

Check Line Endings

Line endings can differ between Unix and Windows systems, which can cause issues when running scripts. Unix systems use \n for line endings, while Windows uses \r\n.

You can use the hexdump command to check the line endings in your script.

hexdump -c

If the line endings are incorrect, you can convert them using tools like dos2unix.


Check File Location

Finally, ensure that you are in the correct directory where the script file is located. If the file is in a different directory, you need to provide the full path while executing the script.

sudo /path/to/


Resolving the “sudo: ./ command not found” error in bash scripts involves checking several aspects, including file permissions, the shebang line, line endings, and file location. By following the steps outlined in this article, you should be able to successfully execute your bash scripts.

Remember, it’s always important to ensure your scripts have the correct permissions and are located in the right directory. Also, be mindful of the differences in line endings between Unix and Windows systems to avoid potential issues.

What does the error “sudo: ./ command not found” mean?

This error means that the shell is unable to locate and execute the script file "".

How can I fix the “sudo: ./ command not found” error?

To fix this error, you can check the file permissions, ensure the shebang line is correct, check the line endings, and verify the file location.

Leave a Comment

Your email address will not be published. Required fields are marked *