Göm meny

Unix - file system

When information is stored in a computer it is stored as files. By storing, we mean physically writing data on e.g. magnetic discs. Files can be grouped together in file directories. The directories are used to separate files and to maintain order in the file system. The directories are sorted in a hierarchial order with the top directory being the base for all files in the system. The topdirectory is called the root ('/').
When given a user ID, you are in fact given a physical space to store information. This is represented by your home directory.

Structure

When your UNIX window is opened you will be 'standing' in your home directory, in the picture below referred to as 'Me'.

filetree

The content in your directory can be displayed with the ' ls' command, for example in the 'Me' directory the command 'ls -l' would produce:

ra>ls -l
-rw-rw-r-- 1  Me 567  Dec  24 15.00  array.p
drwxr-xr-x  1 Me 1027  June 10 10.00  program

picture

This directory consists of two items. One pascal document (shown by the suffix '.p') and one directory called 'program'. We can see that 'program' is a directory by observing the 'd' in the type of file column. After the file type comes the rights (more thouroughly explained later), number of links to the file and the owner/creator of the file. The latest date the file was changed follows and the name of the file ends the line.

Travel in the filesystem

cd directory To change working directory to directory.
cd .. To go up a level in the structure.
cd ../../ To go two steps up in the filestructure.
cd ~ To go to your home directory from all places in the filesystem.
cd ~aaabb123 To go to the home directory of user 'aaabb123' from all places in the filesystem.
pwd Shows the current working directory.

Links

In UNIX it is possible to refer to a file without making an actual copy of it. This is done with the 'ln' command. For example, if you have the file 'array.p' in your home directory and want to reach it easily working in the 'program' directory, a link can be created. If your working directory is 'Me', use following command:

ra> ln -s  array.p program/arr.p

By calling 'arr.p' standing in the '~Me/program' directory the file 'array.p' will be reached.

Protection of files and directories

The UNIX environment provides unique possibilities for protection of documents and directories for each user. You can as a user protect your files from other users in three ways, you can prevent them to read, write and execute your files. In other words:

Right Sign Implies for a file Implies for a directory
Right to read r Allows a user to open and read a document. Allows the user to see the content in the directory with the ls-command.
Right to write w Allows a user to change the document. Allows the user to create documents in the directory.
Right to execute x This allowes a user to execute a program Allows the user to open the directory.

The current rights are easily displayed with the 'ls -l' command:

ra>ls -l 
-rw-rw-r--  1 Me 567  Dec 24 15.00 array.p 
drwxr-xr-x  1 Me 1027 Jun 10 10.00 program 

picture

The rights to a file or directory are divided into three, the owner (ie the creators) rights, the rights of a specified group and the rights of all users on the system. This means as in the example above, that the file 'array.p' can be read and changed by the creator 'Me', it can be read and changed by a specified group which the root can define and it can also be read by all users.

It is only the owner (and root) that can change a file protection. This usually means that you are given the right to change the protection in your own directory but not on other places in the system.

How can I change the file and directory protections? This is made with the 'chmod' command. The command can be given as follows:

ra> chmod 755 array.p 

The numbers represent the rights given in order to the user, group and all users. The number can be one of 0-7. Each number represents a special right:

Number Symbol Right to:
0 --- No rights
1 --x Execute
2 -w- Write
3 -wx Write and execute
4 r-- Read
5 r-x Read and execute
6 rw- Read and write
7 rwx Read, write and execute

In our 'array.p' example the rights of 'array.p' would now be:

-rwxr-xr-x 1 Me 567 Dec 24 15.00 array.p

Informationsansvarig: Kristina Arkad
Senast uppdaterad: 2019-09-03