Lesson 2 – Permissions

Now that you are logged into a Linux machine, the fun begins!

Viewing Permissions

To view the contents of the directory you are in, use the ls command. To do this, at the command prompt (I will represent the command prompt using the “>” (greater-than) sign for the rest of this tutorial.), type the command, then hit the “Return” key:

    >ls

You will see a listing of the files in the directory. To get more information about the files in your directory, add the “l” switch (Switches allow you to modify the output of the command you use.):

    >ls -l

Following is an example of what you may see after running the command above:

    >ls -l 
    -rw-r--r--  1 gt#  student  686982 Oct 26 20:06 image.gif
    drwx------  6 gt#  student     512 Oct 26 19:57 directory1
    drwx------  2 gt#  student     512 Aug 12 17:47 directory2
    -rw-r-----  1 gt#  student    1715 Aug 13 14:46 filename.txt
  • A “-” (dash) in the first column shows that the name listed is for a file, while the “d” shows that it is a directory. Another letter that you may see there is “l”; if there is an “l” in the first column, that means that the “file” is a soft link. A link points to a file (I will explain links in more detail later.)
  • The second column shows the “read” permission for the owner of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The third column shows the “write” permission for the owner of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The fourth column shows the “execute” permission for the owner of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The fifth column shows the “read” permission for the group of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The sixth column shows the “write” permission for the group of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The seventh column shows the “execute” permission for the group of the file. A “-” (dash) in this spot indicates a lack of permission.
  • The eighth column shows the “read” permission for everyone (“world”; anyone who has permission to login to the machine you are on). A “-” (dash) in this spot indicates a lack of permission.
  • The ninth column shows the “write” permission for everyone (“world”). A “-” (dash) in this spot indicates a lack of permission.
  • The tenth column shows the “execute” permission for everyone (“world”). A “-” (dash) in this spot indicates a lack of permission.
  • The eleventh column is the number of links, but is not important for this tutorial, so I will not go over it.
  • The twelfth column is the owner of the file. This is the username of the person who owns the file.
  • The thirteenth column is the group of the file. You can set permissions in such a way that the group has certain permissions that others may not have (like write permission).
  • The fourteenth column is the file size.
  • The fifteenth column is the month that the file was last edited.
  • The sixteenth column is the day of the month that the file was last edited.
  • The seventeenth column is either the time of day that the file was last edited, or, if the file has not been edited for quite a while (less than a year), it show the year that the file was last edited.
  • The final column is the filename.

For more information about the ls command, read the man pages (Note: to get information/help on a command, use the man command in the format of “man commandname“, without quotes, where commandname is the name of the command that you need help on. The example below gives you the manual (“man pages”) for the ls command.)

    >man ls

Changing Owner, Group, and Permissions

Use the chown (“change owner”) command to change the owner for a file:

    >chown username filename

where username is the Linux username (login) of the person who you would like to be the owner of the file; and filename is the name of the file (or directory) that you would like to change the owner for. The owner of the file has permission to run the chown command. For more information, read the man pages:

    >man chown

Use the chgrp (“change group”) command to change the group for a file:

    >chgrp groupname filename

where groupname is the name of the Linux group you would like to set for the file; and filename is the name of the file (or directory) that you would like to change the group for. The owner of the file has permission to run the chgrp command, and must be a member of the group that he/she is changing to (Note: You can use the groups command (just type the word “groups” without quotes at the command line) to see what groups you belong to; the first group listed is your default group.). For more information on the chgrp command, read the man pages:

    >man chgrp

Tip: In order to work “in the context” of a group, use the newgrp command:

    >newgrp groupname

where groupname is the name of the group. An example of a time when you would want to use the newgrp command is when you are working on a project with several other people, all of whom need to be able to edit the file(s). Say you want the files to have the group, “class”, set for them so that other people in the “class” group can edit the files and create new files in a particular directory. You use the groups command and find out that your default group is “student”. Whenever you edit a file or create a new file, the group will probably be set to “student”, so if you use the newgrp command, your “default” group is set to the groupname that you specify.

Use the chmod command to change the read/write/execute permissions for the owner, group, and “everyone” for a file.

    >chmod 644 filename
    >chmod 755 directoryname

The two versions above of the chmod command are the most common. The first one gives the owner read and write permission, the group read permission, and “everyone” read permission to the file, called filename. The second one gives the owner read, write, and execute permission, the group read and execute, and “everyone” read and execute permission for the directory (or file), called directoryname. (Note: In order to change to a new directory, you must have execute permission on that directory; in order to run a script, you must have execute permission on that file/script). Also note: If you are setting up files and directories to be used on a webserver, you must set permissions on files to “world” readable and on directories to “world” readable and executable. Otherwise, the webserver will not be able to read your files to send them out to browsers on other machines.

Continue to Lesson 3 – Moving Around In the Filesystem
Return to index of lessons.

Last revised April 23, 2002.