Question 3.13: You need to change the permissions on a file....

You need to change the permissions on a file.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

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.

Related Answered Questions

Question: 3.34

Verified Answer:

Use the Linux df command: $ df -h Filesystem   ...
Question: 3.33

Verified Answer:

Use the Linux date command. The date and time form...
Question: 3.32

Verified Answer:

Edit the file ~/.bashrc using nano (Recipe 3.6), a...
Question: 3.31

Verified Answer:

Run the program or command in the background using...
Question: 3.30

Verified Answer:

Redirect the output to /dev/null using >. For e...
Question: 3.24

Verified Answer:

Use the Task Manager utility, which you’ll find on...
Question: 3.29

Verified Answer:

Use the pipe command, which is the bar symbol (|) ...
Question: 3.27

Verified Answer:

Use the > command to redirect output that would...
Question: 3.28

Verified Answer:

Use the cat command to concatenate a number of fil...
Question: 3.26

Verified Answer:

Use the lsusb command. This will list all the devi...