Shell Changing Permissions
chmod changes the permissions of a file. Permissions say who is allowed to read, write and run a file.
Add run permission
chmod u+x adds run permission for the owner, u. The x in the listing shows the change.
chmod u+x notes.txt
ls -l notes.txtTake away group write
chmod g-w takes write permission from the group, g.
chmod 660 notes.txt
chmod g-w notes.txt
ls -l notes.txtSet permissions by number
chmod 755 sets read, write and run for the owner, and read and run for the rest.
chmod 755 notes.txt
ls -l notes.txtChange the owner
chown root:root makes root the owner and the group of the file.
chmod 660 notes.txt
chown root:root notes.txt
ls -l notes.txt
chown root:nogroup notes.txtCheck the default
umask prints the default-permission setting. New files start from it.
umaskExample
chmod 644 notes.txt
chmod u+x notes.txt
ls -l notes.txt
umaskKey points
- Permission bits: the nine letters in ls -l that say who is allowed to read, write and run a file.
- Use chmod u+x file to add run permission for the owner of a file.
- Use chmod g-w file to take write permission from the group.
- Use chmod 755 file to set permissions by number, in octal form.
- Octal digits: 7 means read, write and run, and 4 means read only.
- Use chown owner file to change the owner of a file.
- umask: the setting that fixes the default permissions of new files.
In this example, chmod 644 sets read and write for the owner and read for the rest. Then chmod u+x adds run permission for the owner. Next ls -l shows the new permissions. Last umask prints the default-permission setting.
Note
chown to another user needs the right rights on a shared computer.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command sets read and write for the owner, and read only for the group and others?