The command ls -l
lists file properties (details)
[user@host ~]$ ls -l
total 368
-rw-r--r-- 1 course1 ucaac2 167546 Jan 25 2014 11.txt
-rw-r--r-- 1 course1 ucaac2 72 Jun 6 12:34 a_script.sh
drwxr-xr-x 4 course1 ucaac2 4096 Jun 6 12:43 bread
drwxr-xr-x 4 course1 ucaac2 4096 Jun 6 12:41 cake
...
This consists of a number of pieces of information:
drwxr-xr-x 4 course1 ucaac2 4096 Jun 6 12:43 bread
drwxr-xr-x - File type and permissions
4 - Number of links to the file
course1 - User name of file owner
ucaac2 - Group to which the file belongs
4096 - size of file in bytes
Jun 6 - last change date
12:43 - last change time
bread - file name
There are three user security classifications that apply to the ownership of a file:
user: the individual user that has ownership of the file
group: a group of users to which that user belongs
others: all other users (not owner or in that group)
Each of these has three file access classifications:
read: permission to read the file
write: permission to write the file
execute: permission to execute (run) the file
drwxr-xr-x has four fields:
d | The file is a directory |
rwx | The user has read, write and execute access |
r-x | The group has read and execute access |
r-x | Others have read and execute access |
Interpretation of permissions:
Permissions | read | write | execute |
---|---|---|---|
rwx | yes | yes | yes |
rw- | yes | yes | no |
r– | yes | no | no |
r-x | yes | no | yes |
— | no | no | no |
The command chmod
is used to change the permissions of a file.
[user@host ~]$ ls -l
drwxr-xr-x 4 course1 ucaac2 4096 Jun 6 12:43 bread
[user@host ~]$ chmod go-rx bread
[user@host ~]$ ls -l
drwx------ 2 user rcops 4096 2009-12-08 07:31 a_directory
How did the permissions definition go-rx work?
chmod [ugoa][+/-][rwx] file
ugoa - user, group, other, all
+/- - add/remove
rwx - read, write, execute
If you don’t specify u,g,o or a, default is ALL (so chmod +x makes file executable for everyone).
What groups am I in?
[user@host ~]$ groups
ucaac2 legon020
Next activity: Readings - Shell scripts.