r5 - 31 Mar 2005 - 16:22:32 - JimWilgenbuschYou are here: TWiki >  TechHelp Web > WepPageSetup? > DirectoryPermissions

File/Directory Permissions

Use the chmod command to change your file permissions on a file or a directory. The ls -al command will print detailed information for all the files and directories in your current directory.

For example, typing:

ls -al

Will give you:

-bash-2.05b$ ls -al
total 7804
drwxr-xr-x  6 gibbard  bio      512 Feb 15 22:17 .
drwxr-xr-x  4 gibbard  bio     1024 Feb  1 19:23 ..
drwxr-xr-x  2 gibbard  bio      512 Sep 20 13:56 downloads
-rw-r--r--  1 gibbard  bio        0 Feb 15 22:17 file.html
-rw-r--r--  1 gibbard  bio      951 Feb  1 21:43 index.php
drwxr-xr-x  7 gibbard  bio     2560 Jan 27 13:28 phpMyAdmin
-rw-r--r--  1 gibbard  bio  7936000 Jan 25 21:01 phpMyAdmin-2.6.1.tar
-rw-r--r--  1 gibbard  bio       22 Nov 16 13:55 phpinfo.php
drwxr-xr-x  3 gibbard  bio      512 Sep 21 05:20 projects

The output of ls -la explained

  • -bash-2.05b$ This is your shell prompt. This will differ according to the shell you are using.
  • ls -al This is the command that was run in order to retrieve the results.
  • drwxr-xr-x This sting represents the file permissions. Changing these values will determine whether other users can view, change or execute the file.
  • gibbard The file owner's username.
  • bio The file owner's principal group.
  • 512, 1024, 512, etc.. Is the size of the file in kb followed by the date and time the file was created or altered.
  • *., .., downloads, file.html, etc * Are the files or directories.

Note: Files or directories preceeded by a dot (.) are only visible when running the ls -al command not the ls command. -al Denotes "all" and "list".

File permissions explained

We'll use the downloads directory from the list output above to briefly explain file permissions.

drwxr-xr-x  2 gibbard  bio      512 Sep 20 13:56 downloads

File permissions are represented by a string of ten characters. The first character tells you what kind of file you have. Typically this is either a d for a directory or a - for a file. The remaining nine characters can be divided into three groups of three characters. The characters represent the file permissions for the user (file owner), the group, and other (everyone who can access the file system), respectively. This allows the file owner to separately enable/disable read (r), write (w), or execute (x) permissions on a file or directory for the three classes of users.

file type user group other
d rwx r-x r-x

The letters r,w,x will appear if the corresponding permissions are enabled for the corresponding class of user. Otherwise, the absence of a letter (-) means that the corresponding permission is disabled.

Following the permissions string is a number, which represents the number of files in the directory (this is always one in the case of a file). After this, you will find the file owner and the file group names, which correspond to the user and group, respectively.

How to change file permissions

Note: As long as you are the owner of the file or directory you can change the permissions.

     The command chmod is used to change the permissions of a file or directory.
     chmod 777 filename will result in rwxrwxrwx permissions.
     chmod 000 filename will result in --------- permissions (no permissions for anyone)
    
     Each number represents a set of permissions.

     Example: 7 = rwx, 7 = rwx, 7 = rwx

     Each letter contains a total value of 7
     r has a value of 4
     w has a value of 2
     x has a value of 1

     Example: chmod 644 filename
              chmod 004 filename
              chmod 430 filename
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r5 < r4 < r3 < r2 < r1 | More topic actions
 
SCS TWiki

This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback