Command not found when using sudo
Permission denied
In order to run a script the file must have an executable permission bit set.
In order to fully understand Linux file permissions you can study the documentation for the chmod
command. chmod, an abbreviation of change mode, is the command that is used to change the permission settings of a file.
To read the chmod documentation for your local system , run man chmod
or info chmod
from the command line. Once read and understood you should be able to understand the output of running ...
ls -l foo.sh
... which will list the READ, WRITE and EXECUTE permissions for the file owner, the group owner and everyone else who is not the file owner or a member of the group to which the file belongs (that last permission group is sometimes referred to as "world" or "other")
Here's a summary of how to troubleshoot the Permission Denied error in your case.
$ ls -l foo.sh # Check file permissions of foo
-rw-r--r-- 1 rkielty users 0 2012-10-21 14:47 foo.sh
^^^
^^^ | ^^^ ^^^^^^^ ^^^^^
| | | | |
Owner| World | |
| | Name of
Group | Group
Name of
Owner
Owner has read and write access rw but the - indicates that the executable permission is missing
The chmod
command fixes that. (Group and other only have read permission set on the file, they cannot write to it or execute it)
$ chmod +x foo.sh # The owner can set the executable permission on foo.sh
$ ls -l foo.sh # Now we see an x after the rw
-rwxr-xr-x 1 rkielty users 0 2012-10-21 14:47 foo.sh
^ ^ ^
foo.sh is now executable as far as Linux is concerned.
Using sudo results in Command not found
When you run a command using sudo you are effectively running it as the superuser or root.
The reason that the root user is not finding your command is likely that the PATH
environment variable for root does not include the directory where foo.sh
is located. Hence the command is not found.
The PATH environment variable contains a list of directories which are searched for commands. Each user sets their own PATH variable according to their needs.
To see what it is set to run
env | grep ^PATH
Here's some sample output of running the above env
command first as an ordinary user and then as the root user using sudo
rkielty@rkielty-laptop:~$ env | grep ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
rkielty@rkielty-laptop:~$ sudo env | grep ^PATH
[sudo] password for rkielty:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
Note that, although similar, in this case the directories contained in the PATH the non-privileged user (rkielty) and the super user are not the same.
The directory where foo.sh
resides is not present in the PATH variable of the root user, hence the command not found error.
Command not found while using sudo [UBUNTU 19.04]
This will work
$ sudo /opt/lampp/lampp start
Provided that your installation path is /opt/lampp
which is the default path.
If the installation path is unknown try which lampp
and then start from there.
Related Topics
How to Tar a Directory Without Retaining the Directory Structure
Multiple Glibc Libraries on a Single Host
How to Compare Two Strings in Dot Separated Version Format in Bash
Get Exit Code of a Background Process
How to Get Process Id of Background Process
Nasm Segmentation Fault on Ret in _Start
Have Bash Script Answer Interactive Prompts
Find and Replace With Sed in Directory and Sub Directories
How to Determine Whether a Given Linux Is 32 Bit or 64 Bit
How to Use the Lines of a File as Arguments of a Command
Get Most Recent File in a Directory on Linux
Imagemagick Security Policy 'Pdf' Blocking Conversion
How to Redirect Output of an Already Running Process
How Does Mmap Improve File Reading Speed
What Is the Meaning of a Double Dollar Sign in Bash/Makefile
How Do Linux Binary Installers (.Bin, .Sh) Work
Defining a Variable With or Without Export
How to Programmatically "Burn In" Ansi Control Codes to a File Using Unix Utils