GRABNOTES

File permissions

Home

File attributes:

read only(r) - Users can read the file but cannot modify or execute it.
write(w) - Users can read and modify the file.
execute(x) - Users can run the file.

User categories:

user(u) - The owner of the file(For eg: The managing director of the company)
group(g) - File access to users in its group(For eg: All employees working for the  Human Resource Department in a company)
others(o) - File access to every other user in the network(For eg: Every other employee in the company)

Displaying file permissions:

You can display the file permissions in the current directory by typing,
$ls -l

For a specific file or directory type,
$ls -l (directory/file name)

Your output would be something like,

total3
-rwxr-xr-- 1 jamie HR 907 Oct 17
13:32 picture.gif
-rw-r--r-- 1 katie finance 11884 Sep 15
23:20 video.html
-rwx------ 1 pete sales 821 Aug 11
10:15 lab

The first character is usually a '-' or a 'd'. '-' indicates a file, 'd' indicates a directory.
The next three characters define the file permissions for the user,
the next three for the group and
the final three for others on the network.

Lets take picture.gif. The first '-' indicates that it is a file and the file permissions for the three user categories are as follows

Owner Read Write
Execute
Group Read - Execute
Others Read - -


Changing file permissions - chmod


chmod is used to change file permissions.

If you would like to see what is really happening to the file, use verbose mode
#chmod -v

To apply changes to all files and directories under the current directory, use -R,
#chmod -R

The various user options for chmod is given below:

User options
u for users
+ for add r for read
g for group - for remove w for write
O for others
  x for execute

For example, if you would like to change the file permissions of lab from -rw------- to -rw-r-xr-x, you need to type,
#chmod go+rx
i.e., you are giving read and execute access to the group as well as others

Other examples are,

#chmod ugo+rwx (file/directory name)
which gives read, write and execute access to all users.


#chmod go-w (file/directory name)
which removes the write privileges of group and others from modifying the file.



Changing the owner - chown

The owner of a file could be changed by using the chown command.

#chown (username/new owner) (file/directory name)


Changing the group - chgrp

The group to which the file belong can be changed using the chgrp command

#chgrp (groupname) (file/directory name)