You may see a Permission denied error when you try to execute a Python, Shell, or Bash scripts on Linux distributions, Unix, or macOS Terminals.
Example: zsh shell on macOS
% ./script.sh zsh: permission denied: ./script.sh
Example: Sh Shell
# ./script.sh bash: ./script.sh: Permission denied
Example: Bash Shell
$ ./script.sh sh: ./script.sh: Permission denied
Now let's take a look at file permissions using ls command on the script.sh file.
% ls -ls script.sh 0 -rw-r--r-- 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
Let's try to understand what permissions we have on the file using a table.
As you can see not of the users have the execute permission enabled, hence the erorr.
Let's make use of chmod +x on the file.
% chmod +x script.sh % ls -l chmod+x script.sh -rwxr-xr-x 1 c2ctechtv staff 0 Jul 16 02:49 script.sh
Conclusion: As you can see after executing chmod +x on a file, all the users/groups/others get the rights to execute the file.
Facing issues? Have Questions? Post them here! I am happy to answer!
- Rename a directory using Linux/Unix command
- ls command to list only directories
- How to Restart or Reload Nginx Server Service on Linux
- 3 ways to clear screen on Linux Terminal
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: sudo: unable to open Read-only file system
- Create Hidden File or Directory using Shell Command
- Command to know the installed Debian version?
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - bash: man: command not found
- How to tar.gz a directory or folder Command
- How to Display content of a file in Terminal Screen?
- How to change bash terminal prompt string and color
- Sort ls command by last modified date and time
- Execute .bin and .run file Ubuntu Linux
- zsh hello world example
- How to check uptime of Linux/Unix/macOS system/server using console command?
- [Fix] Linux - bash: useradd: command not found
- Command to check Last Login or Reboot History of Users and TTYs
- How to install and Configure sar sysstat tools in Ubuntu Linux
- How to use SCP Command to Copy Directory
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to connect to SSH port other than default 22
- Install OpenSSL on Linux/Ubuntu
- SharePoint Server 2016 Preview installation error - This Product Key isn't a valid Microsoft Office 2016 Product Key. Check that you've entered it correctly. - SharePoint
- Eclipse: Updating Maven Project. Unsupported IClasspathEntry kind=4 - Eclipse
- Android Studio : Build Tools 23.0.0 rc1 is deprecated - Android-Studio
- Reading .xls and .xlsx Excel file using Apache POI Java Library - Java
- Delete a Directory using Mac Terminal Command - MacOS
- How to Search Maven Central Repository - HowTos
- MongoDB: Failed to connect to 127.0.0.1:27017 reason: Connection refused - HowTos
- How to disable Siri on Mac Monterey - MacOS