Change File Permissions in Ubuntu Command Line
Q: How would you change file permissions using the command line in Ubuntu?
- Ubuntu
- Junior level question
Explore all the latest Ubuntu interview questions and answers
ExploreMost Recent & up-to date
100% Actual interview focused
Create Ubuntu interview for FREE!
To change file permissions using the command line in Ubuntu, you would use the `chmod` command. This command allows you to modify the read, write, and execute permissions for the file owner, the group, and others.
The basic syntax of the `chmod` command is:
```
chmod [options] permissions file
```
Permissions can be specified in symbolic form (using letters) or numeric form (using octal numbers).
1. Symbolic Method:
- For example, if you want to give the owner execute permission on a file named `script.sh`, you would use:
```
chmod u+x script.sh
```
- Here, `u` stands for the user (owner), `+` adds the permission, and `x` is for execute permission.
2. Numeric Method:
- Permissions can also be set using octal numbers, where read is 4, write is 2, and execute is 1. For instance, to set read and write permissions for the owner, and read permissions for the group and others, you would use:
```
chmod 644 file.txt
```
- In this example, `6` (4+2) grants read and write to the owner, and `4` grants read permission to both the group and others.
Using `chmod` effectively allows you to manage access control on your files, ensuring that users have the necessary permissions based on their roles.
The basic syntax of the `chmod` command is:
```
chmod [options] permissions file
```
Permissions can be specified in symbolic form (using letters) or numeric form (using octal numbers).
1. Symbolic Method:
- For example, if you want to give the owner execute permission on a file named `script.sh`, you would use:
```
chmod u+x script.sh
```
- Here, `u` stands for the user (owner), `+` adds the permission, and `x` is for execute permission.
2. Numeric Method:
- Permissions can also be set using octal numbers, where read is 4, write is 2, and execute is 1. For instance, to set read and write permissions for the owner, and read permissions for the group and others, you would use:
```
chmod 644 file.txt
```
- In this example, `6` (4+2) grants read and write to the owner, and `4` grants read permission to both the group and others.
Using `chmod` effectively allows you to manage access control on your files, ensuring that users have the necessary permissions based on their roles.


