what


LINUX

After a semester of my making you use LINUX, I will now add some information that a Computational Physicist needs to know in order to use LINUX for scientific programming. Phelafel, tx/aluf and TAMNUN are all LINUX. Some of this comes from questions asked during the course and some is just stuff I think is important. On LINUX machines shared by several users a user called root is the superuser; some things have to be done by root, but you can do a lot in your own account too. On Ubuntu and cygwin its a bit different, you can do everything. This can be dangerous.
  1. On a linux machine there are two places you can keep files temporarily. One is /tmp, the other /var/tmp - anyone can write there, but the systems people can also wipe them when they want to. This is good for temparary use while transporting files or compiling. Don't count on it staying there.
  2. to swap all strings AAA with BBB in all files in directory:
    sed -e 's/AAA/BBB/g' -i *.*
    (thanks to ariella)
  3. There are several standard ways of archiving and distributing code. If you download files from the web some of this might help you.
    1. tar files: lets assume we have a lot of files in a directory, and we are located in that directory. We can archive them by writing ``tar -cvf allmyfiles.tar *'' - this packs them into a binary file called allmyfiles.tar which can then be moved around with scp or downloaded from a web or http server. You unpack it with ``tar -xvf allmyfiles.tar'' - it preserves also subdiectories but will write over a file you have with the same name. tar files can be gzipped to make them smaller. Sometimes files have anending .tgz which means they are both tarred and gzipped. For example: tar -zxvf g95-x86-linux.tgz unpacks the g95 compiler. IF you are installing this a useful command is ln -s $PWD/g95-install/bin/*g95* ~/bin/g95to give a symbolic link from a directory in your path.
    2. redhat uses a format called rpm for distributing compiled files. I quote: `` RPM is the Red Hat Package Manager. It is an open packaging system available for anyone to use. It allows users to take source code for new software and package it into source and binary form such that binaries can be easily installed and tracked and source can be rebuilt easily. It also maintains a database of all packages and their files that can be used for verifying packages and querying for information about files and/or packages.''
      You use it by finding the rpm you want on the web, (lets call it rpm -i foobar-1.0-1.i386.rpm) downloading and writing
      rpm -i foobar-1.0-1.i386.rpm
      
      It might tell you you need another package to, so find it and then install both. An example of code distributed by rpm is AViz.
  4. Compiling code: We have used so far f77, f95, cc etc, to compile a single file. When several files have to be compiled and linked, something called a Makefile is used. The best explanation is on the GNU website. I quote a little:
    ``To prepare to use make, you must write a file called the makefile that
    describes the relationships among files in your program and provides
    commands for updating each file. In a program, typically, the
    executable file is updated from object files, which are in turn
    made by compiling source files.
    
    Once a suitable makefile exists, each time you change some source files, 
    this simple shell command:
    
         make
    
    suffices to perform all necessary recompilations. The make program 
    uses the makefile data base and the last-modification times of the 
    files to decide which of the files need to be updated. For each of 
    those files, it issues the commands recorded in the data base. 
    
    The file should be  called Makefile (the capital places it near the top of
    the ls list).
    
    an example is
    
    edit : main.o kbd.o command.o display.o \
                insert.o search.o files.o utils.o
                 cc -o edit main.o kbd.o command.o display.o \
                            insert.o search.o files.o utils.o
         
         main.o : main.c defs.h
                 cc -c main.c
         kbd.o : kbd.c defs.h command.h
                 cc -c kbd.c
         command.o : command.c defs.h command.h
                 cc -c command.c
         display.o : display.c defs.h buffer.h
                 cc -c display.c
         insert.o : insert.c defs.h buffer.h
                 cc -c insert.c
         search.o : search.c defs.h buffer.h
                 cc -c search.c
         files.o : files.c defs.h buffer.h command.h
                 cc -c files.c
         utils.o : utils.c defs.h
                 cc -c utils.c
         clean :
                 rm edit main.o kbd.o command.o display.o \
                    insert.o search.o files.o utils.o
    
    (The \ is a line continuation)
    
    
    You run this by writing the command ``make'' and its to be assumed that all the files .c and .h are present in the directory or in your path. More advanced things on the gnu website.''
See link here , for material (prepared by Zaher Salman) on LINUX in Hebrew.

This page was last updated on December, 2012

Back to the index page