Let's say there is a file we would like to execute, a bash script named add.sh
, for example. Typing ./add.sh
however, yields a permission error. Getting the permissions is a simple process.
To determine the permissions a file has, type:
ls -l filename
, or, in our case, ls -l ./add.sh
This prints the following to the console:
-r--r--r-- 1 username groupname 0 Jan 4 12:00 add.sh
Let's stop and understand what this means. There are three different types for permissions: owner, group, others. Distinct permissions apply to each permission type.
There are also three permission actions, which more broadly also describe what exactly a user can do to a file. These are: (read: r, write: w, execute: x).
So, back up to that string of dashes and r's. Each permission group has three potential abilities. The groups are listed in the order owner-group-others
and the actions as read-write-execute
.
But wait, that means there's an extra character at the beginning of the string. This is actually the file descriptor character. We can see there is a -
there, but other characters exist for things like directories(d)
, sockets(s)
, symbolic link(l)
etc.
This leaves us with essentially this information: a file where owner, group, and others have read permissions. No other permissions granted.
Let's alter this to allow the owner to also write and execute the file. Note: Depending on the permissions, it may be necessary to prepend sudo
to this command.
chmod 744 add.sh
ls -l add.sh
Prints out
-rwxr--r-- 1 username groupname 0 Month time add.sh
Now, the owner of the file can execute the file by typing
./add.sh