Document Sample
LINUX OS Powered By Docstoc
					Mem. S.A.It. Suppl. Vol. 8, 78
                                                                     Memorie della
c SAIt 2005

Introduction to LINUX OS for new LINUX users
             – Basic Information Before Using The Kurucz Codes Under LINUX–

                                                ¸    ¸
                                           M. Taskın Cay

       ˙         ¨                    u                                    ou u
       Istanbul Universitesi, Fen Fak¨ ltesi, Astronomi ve Uzay Bilimleri B¨ l¨ m¨ , 34119,
       Universite, ˙
                   Istanbul / Turkey.

       Abstract. Recently the ATLAS suite (Kurucz) was ported to LINUX OS (Sbordone et
       al.). Those users of the suite unfamiliar with LINUX need to know some basic information
       to use these versions. This paper is a quick overview and introduction to LINUX OS. The
       reader is highly encouraged to own a book on LINUX OS for comprehensive use.
       Although the subjects and examples in this paper are for general use, they to help with the
       installation and running the ATLAS suite.

       Key words. Operating Systems: LINUX – Model Atmospheres: ATLAS9, ATLAS12

1. Introduction                                       1.2. Which LINUX distribution should I
1.1. Why should I use LINUX OS?
LINUX is now a widely used operating system.
For a general user there can be many reasons to       Today, hundreds of LINUX distributions
prefer LINUX OS for everyday use;                     can be found: RedHat, Slackware, SUSE,
                                                      Mandrake, ...etc. Although the names are dif-
    1- it is free,
                                                      ferent, all LINUX distributions still have the
    2- it comes with many programs including          same kernel. Thus in theory any program
an office suite,                                        should run under any LINUX distribution.
    3- security in LINUX is high,                     Nevertheless, using the pre-compiled binary
    4 - it is an open source operating system -       executables to run a program generally re-
you can change the system as your wish; even          quires the same LINUX distribution under
create your own private LINUX distribution.           which they have been compiled. The best way
    For a scientific user we may add three more        to be sure that a program will run in your PC
important reasons;                                    without trouble, is having the source code of
    1- it is a very stable system - LINUX can         the program and compiling it yourself in your
easily handle multiple tasks and runs for a long      PC.
time without crashing,
    2- it allows parallel programming,                     The question can simply be answered as
    3- it turns an ordinary PC to an UNIX             you can use any LINUX distribution you enjoy.
workstation.                                          It is only a matter of comfort.
                                   Cay: Introduction to LINUX OS                                   79

2. Basics of LINUX                                      The most used shell and also the default
                                                    is the bash shell, so it should also be left un-
2.1. Users, user rights and file                     changed. A shell is a program that interprets
     permissions                                    the commands you have given to the system.
LINUX is a multi-user and multi-tasking oper-       For example, when you write pico in the ter-
ating system. Thus the system can be used by        minal screen 2 (means in the command-line)
more than one user in the same time and can         then enter, the shell understands that you want
perform multiple operations simultaneously.         to run the program pico that is a text editor,
    The users of the system have limited rights     and starts the program if installed in your sys-
to use the system and these rights are given by     tem. There are also several other shells such
the system administrator who has access to the      as csh (C shell), sh or tsch etc. Generally, us-
root account 1 .                                    ing any shell is a matter of comfort and there
    Each user has a private directory called        are little differences between shell commands.
home, in the system. This is the main working       Sometimes a specific program can require use
directory of the user. The users cannot reach       of a specific shell. The user can switch between
and modify the other directories and files ex-       shells using chsh command. For example, typ-
cept for the shared ones.                           ing
    On the other hand the root has unlimited            chsh csh
rights; it can reach and modify all the directo-    changes the shell to the C shell.
ries and files. Although being unrestricted may          Several users can be grouped together to
seem funny, using the system as root can be         give them specific group rights (see the next
dangerous; because you may delete an impor-         section). A group can be added to the system
tant file or make hazardous changes in the sys-      with a in similar way to adding a user.
tem accidentally. To avoid such troubles it is
better to login to the system as an ordinary user   2.1.2. Permissions
for everyday use. In general we may say that:
    - Login to the system as user for everyday      Each file or directory in the system can be used
use or private installation of a program etc.       by three types of user:
    - Login to the system as root, if you are go-       1- the owner of the file (the user),
ing to make changes to the system (like up-             2- the group,
grading the system itself) or system wide in-           3- the others.
stallation of a program etc.                        For each of these kinds of users, there are
                                                    three types of permissions: read permission (r),
                                                    write permission (w) and execute permission
2.1.1. Creating a user account                      (x). Permissions determine who can read the
The easiest way to create a user account is         file (or the directory), who can write to the file
to use the graphical user interface (GUI).          or directory (this means who can modify the
Depending on the LINUX distribution and/or          file or directory) or who can execute the file (it
the desktop environment (GNOME or KDE)              should be noted that in LINUX any file can be
you are using, it may be found in different          executable and it is not necessary to have an
places, but in any case it should be reachable      extension like .exe)
from the start menu. Fig. 1 shows adding a user         To see the file permissions in the current di-
account into the system in the SUSE Linux           rectory the ls command can be used with the -l
case.                                               flag. Please refer to the manual pages and in-
    If there is no reason to do so, the default     formation pages to learn about the syntaxes for
home directory should not be changed.                2
                                                         The terminal screen should be reachable from
    Management of the user accounts and file per-    quick launch bar at the bottom of the screen shown
missions can only be done by the root.              as a monitor icon.
80                                  ¸
                                    Cay: Introduction to LINUX OS

Fig. 1. A user account can be created using a GUI application.

any command and to get info about it. 3 When          /usr/local/kurucz directory. Permissions for this
you type ls -l you will get an output something       file are rwxrwxrwx meaning that all three types
like in Fig. 2. In this example we see some files      of users can read, write and execute this file.
and a directory that are present in the current       The letter l before the permissions indicates
directory. For example, permissions for the file       that this file is a link.
readme.txt are those:                                      Ownership of a file or directory can be
-rw-r- -r- -                                          changed using the chown command:
    rw-: the owner can read and write but can              chown -R taskin
not execute the file.                                  would recursively change the ownership of the
    r- -: the group (means members of the             file (which is formerly belongs to
group users) can read the file but can not write       root) to the user taskin. The same procedure
or execute.                                           is true for changing the group ownership using
    r- -: all other users can read the file but can    the chgrp command.
not write or execute.                                      Permissions of a file can be changed using
    On the other hand the file kurucz is               the chmod command. Using this command re-
a link pointing to the files at the location           quires a little bit of mathematics:
 3                                                         r permission has value of 4
   For example, to learn about how to use the ls
                                                           w permission has value of 2
command, in the terminal screen type: man ls . Also
compare with info ls
                                       Cay: Introduction to LINUX OS                                          81

Fig. 2. Listing of a directory in the long format using the -l flag. The first column shows the permissions in
ten digits; the first letter shows the kind of the file: d for a directory, l for a link, and – for a file. The next
three letters indicates the user (owner)’s rights, following three are for the group rights and the last three
for the others. r for the read permission, w for the write permission and x for the execute permission; blank
(–) means no permission for the relevant type. The second column shows the number of links; for example,
the works directory has two files while the others are only one file. The third and fourth columns show the
owner and the group of the file. The fifth column indicates the length of the file in bytes. The last three
columns are straightforward.

    x permission has value of 1                           dard directories in the root directory and most
Hence, for instance, if a file has permissions             are system directories and cannot be reached
something like                                            by the users. Descriptions of some of these di-
    rwxr-xr-x,                                            rectories follows:
then its value is 755 (rwx: 4+2+1=7, r-x:                     bin: The executables needed to boot the
4+0+1=5, r-x: 4+0+1=5). So,                               system are here. It is also home for some very
    chmod -R 765                                 commonly used LINUX commands. An exe-
would change the permissions of the file                   cutable not need to be binary, it can be a shell as rwxrw-r-x.                                    script. When you install a program, the exe-
    An alternative numeric format is the use of           cutables should not be put here.
symbolic format. Let us assume that the file                   home: Includes all the individual directo- has rwxrwxrwx permissions. Then                  ries of the users.
u,g and o show the user, the group and the oth-               media: Removable drives (cdrom, floppy,
ers, respectively,                                        zipdrive ...etc) are mounted here. mnt direc-
    chmod -R g-w,o-w                             tory does the same thing. Some LINUX distri-
would set the permissions as rwxr-xr-x (g-                butions only have a mnt directory. It is recom-
w means w permission is removed from the                  mended to read the manual pages of the mount
group. To add the permission again use g+w).              command to mount a drive to this directories.
    chmod -R g-x,o-w                                 opt: Includes the files which are not nec-
sets the permissions as rwxrw-r-x. Note that              essary to run the system. For example, the
since nothing is told about the user (u) in               LINUX version of the ATLAS suite can only
the examples the user will have the all rights.           be compiled with Intel Fortran Compiler (ifc),
Again,                                                    so you would need it in your system. The ifc
    chmod -R +x                                  compiler is installed in the opt directory.
would give the x permisson to all three type of               usr: Some other LINUX system files
users. See the manual pages for details.                  which are not necessary to boot the system are
                                                          here. /usr/local directory, which is our main
2.2. Directory structure of the system                    interest in this paper, is for local program in-
                                                          stallations; Fig. 4 shows the structure of this
It is useful to know about some standard di-              directory.
rectories of LINUX OS. Fig. 3 shows the stan-
82                                   ¸
                                     Cay: Introduction to LINUX OS

Fig. 3. Standard directories in the root directory. Please note that root directory does not mean the root’s
home directory; the root directory is at the top of all directories (as shown in the figure, the cd / command
takes you from any directory to the top directory). Root’s home directory can be seen in the figure with the
name of root. Notice that, as an exception and apart from the other users, the home directory for the root is
not under the home directory.

Fig. 4. The /usr/local directory. Source files can be kept in src, compiled or pre-compiled binaries should
be put into the bin directory. Manual pages, libraries and include files of the installed programs have to
be put into the relevant directories. The ATLAS suite can be installed here for a systemwide and clean

2.2.1. Why should I put my programs                     because it is in the current directory. Just type
       into the /usr/local directory?                   in the command-line that:
                                                            ./ nameoftheexecutable
When you call an application (program) from             but this is an uncomfortable way because the
the command-line by typing the name of the              user cannot call the program from other direc-
executable, the shell starts to search the exe-         tory than program’s directory. To run the pro-
cutable through some directories – it does not          gram from another directory each time the user
look at all the directories. These particular di-       has to write the exact adress (full paths) to the
rectories are said to be ”on the path”. If your         program such as,
executable is not in a directory which is on the            /home/taskin/atlas/atlas9/atlas9 mem.exe
path, then the shell cannot find it and cannot           Sometimes writing the full path in script mode
start the program.                                      can be useful to ensure that the correct
    Thus you should put your executable on the          program is running.
path. The easiest way doing this is to put the              2-Adding the directory on the path: This
executable into usr/local/bin directory which           can be done by using the PATH environment
is on the path as default and used for this pur-        variable (see Fig. 5). The PATH variable shows
pose.                                                   which directories will be searched for the exe-
    Also there are ways to executing a program          cutable when a program called from command-
in other directories which are not on the path:         line. A directory can be added in two ways:
    1-Using ./ command : ./ command tells the               i-Temporarily: Type in the command-line
shell that not to search path for the executable        that: export PATH=$PAT H : /exact/adress/o f the/directory.
                                    Cay: Introduction to LINUX OS                                     83

Fig. 5. The shell keeps track of a number of special variables, the environment variables. Environment
variables can be listed on the screen using command env (note that this command is for bash shell; if you
are using another shell, then the command can be different). The Figure shows some of the environment
variables. Each directory that will be searched for the PATH variable, is separated with ”:” sign.

The directory will temporarily be added on the             A link can be tought as a second file name
path until you logout from the system.                pointing the original file and should not be con-
    ii-Permanently: Write the same command            fused with a copy of the original file. Hence,
into the .profile file and save. .profile file is a       the same file is reachable with two different
hidden file in your home directory (to see it use      name. It can be created using the ln command:
the ls command with -a flag in your home di-                ln originalfilename secondfilename
rectory) and is read by the system each time          This kind of link called as hard link. In this
you logon. Hence, when you logon the sys-             case when the original file name is deleted, the
tem the directory automatically added on the          file is reachable using the second file name.
path..profile file can be opened by any text edi-            Hard links sometimes can be problematic,
tor (for example, pico, emacs, Kate, vim... etc).     and for normal users, if there is no other rea-
Type the following command in the command-            son, it is highly recommended that using a sym-
line while in your home directory                     bolic link instead. A symbolic link can be cre-
    pico .profile                                      ated using the ln command with -s flag:
                                                           ln -s originalfilename secondfilename
                                                      In this case, when the original file is deleted the
2.3. Links                                            link is also unreachable (but the reverse is not
Sometimes a program wants to read a neces-            true).
sary file from another directory apart from the             You can see and use the linked file from the
current directory. In this case it might be de-       current directory as if it was there, but actually
sirable to put a link to the remote file from the      it is not there physically. Since the ODF files
current directory. Such a case can frequently         require a large amount of disk space, putting a
occur while running ATLAS suite; For exam-            symbolic link to the ODF files instead of copy-
ple, ODF files would probably be in another di-        ing them into the current directory would be
rectory than the working directory of ATLAS9,         logical.
to save space.                                             See the manual pages or more information
                                                      on the ln command.
84                                   ¸
                                     Cay: Introduction to LINUX OS

Fig. 6. A sample script for running ATLAS9. The first four lines assign the necessary files to the Fortran
input files using symbolic links. Hence, these files can be read by the program from the current directory
with the suitable input file name. # sign in the third line tells the shell to ignore this line. The sixth line
executes ATLAS9 in the current directory and reads (<< sign) the remaining lines (up to the end of file
(EOF)) into ATLAS9 as input. After the model calculation finished, it writes (> sign) the output creating
a file named ap00t10000g40k2odfnew.out. Then in last two lines it moves (renames) the fort.7 output file
into the and removes (deletes) all the Fortran input/output files.

2.4. Shell scripts                                      ation. The following example shows the steps
                                                        of writing a script:
Linux shells are programmable. This roughly                  1- Open a new file. .sh or .com extention
means that several shell commands can be                can be added to the filename to indicate that it
written to a file which then can be executed             is a shell script, but this is not a must:
like a program. Hence, you can avoid retyping                pico
a sequence of commands each time for an oper-
                                    Cay: Introduction to LINUX OS                                       85

    2- Write the commands. For example, the           RPM (RedHat Package Management). For example,
following commands open a new file named               in Debian Linux case installation file has .deb exten-
output and write the word hello into the file          tion and can be unpackaged using dpkg utility.
then create a symbolic link between the out-          name.tgz; the package is archived as tarball and
put and outputlink. Hence, when the script ex-        compressed with gzip. In this case the general runs, two files (output and outputlink)       follows:
will be created in the current directory.                 i- Uncompress the file. In the case of gzip
    echo ”hello” > output                             this can be done typing
    ln -s output outputlink                               gunzip filename.tar.gz
    3- Exit from the pico saving the file.             In other cases of compression (for example, .Z
    4- Make the file executable –otherwise the         or .bz2,...etc.) use the suitable procedure to un-
file is just a text (ASCII) file.                       compress the file.
    chmod + x                                  ii- Open the tarball. To do that type
Now the file can be executed,                              tar -xvf filename.tar
    ./                                          iii- Read the installation instruction file and
    Because this script is written using the          the readme file. These files generally include
bash shell commands, it may not run under             important information about the installation of
other shells (for example under the C shell). To      the program.
avoid such a problem, the following line can be           iv- If there is a Makefile, make the neces-
added to the top line, before the commands:           sary changes in this file and save. Makefile can
    #!/bin/bash                                       be edited using any text editor.
For the other shells, the situation is straightfor-       v- If there is a configuration file type
ward; if the shell is written in C shell for exam-        ./configure
ple, then this line will be #!/bin/csh ... etc.           vi- Type make
                                                          vii- Type make all and/or make install.
                                                          After all those steps have been completed,
2.5. Installing a program                             the program is installed and should be running
A program to be installed can come in two va-         properly.
     1- As a RPM installation file 4 : In this case    3. A sample shell script for ATLAS9
     rpm -i filename.rpm                               A sample script for running ATLAS9 is shown
is enough to install the program. Even simply         in Fig. 6. The reader may prepare his/her own
clicking on the file can start the installation.       script.
     2- As a pre-compiled binary or source
                                                      Acknowledgements. This work was supported by
code: If it is pre-compiled binary, then the bi-
                                                      the Research Fund of the University of Istanbul.
nary has to be put in a directory that is on          Project number: UDP-529/07062005.
the path. For example /usr/local/bin is ideal for          I thank Dr. Barry Smalley who read the draft of
this purpose. If there are also additional files       this paper and made comments concerning its clar-
like library files to run the program then they        ity.
also have to be put into a proper directory like
     If the program comes as a source code,           References
it looks something like filename.tar.gz or file-        Kurucz, R. L. 1993, CDROM 13, 18
    Some of the linux distributions can use differ-    Sbordone, L. et al. 2004, MSAIS, 5, 93
ent kind of package management systems other than     Sbordone, L. 2005, MSAIS, 8, 61

Shared By: