You need to change the permissions on a file.
The command chmod is used to modify file permissions.
Discussion
Common reasons why you might want to change file permissions include needing to edit a file that is marked as read-only and giving a file execute permissions so that it can run as a program or script.
The chmod command allows you to add or remove permissions for a file. There are two syntaxes for doing this; one requires the use of octal (base 8) and the other is text-based. We will use the easier-to-understand text method.
The first parameter to chmod is the change to make, and the second is the file or folder to which it should apply. This change parameter takes the form of the permission scope (+, -, = for add, remove, or set, respectively) and then the permission type.
For example, the following code will add execute (x) rights to the file for the owner of the file file2.txt.
$ chmod u+x file2.txt |
If we now list the directory, we can see that the x permission has been added.
$ ls -l total 16 -rw-r–r– 1 pi pi 5 Apr 23 15:23 file1.txt -rwxr–r– 1 pi pi 5 Apr 24 08:08 file2.txt -rw-r–r– 1 pi pi 5 Apr 23 15:23 file3.txt drwxr-xr-x 2 pi pi 4096 Apr 23 15:23 mydir |
If we wanted to add execute permission for the group or other users, then we could use g and o, respectively. The letter a will add the permission to everyone.
See Also
For background on file permissions, see Recipe 3.12.
See Recipe 3.14 for changing file ownership.