An Introduction to Unix Sylvia Plöckinger March 3, 2011 Sylvia Plöckinger () An Introduction to Unix March 3, 2011 1 / 29
General Information Find this file on: http://homepage.univie.ac.at/nigel.mitchell/numprac/ Sylvia Plöckinger () An Introduction to Unix March 3, 2011 2 / 29
Outline 1 Astro Lab 2 Unix Basics 3 Editors 4 Data Security (unet) 5 Tips for lazy users 6 Fortran - Part I Sylvia Plöckinger () An Introduction to Unix March 3, 2011 3 / 29
Astro Lab How to use the computers in the lab Documentation www.univie.ac.at/astro/internal/lab/ (Unet Login) Start up Enter UserID (student1-12) and password (keyboard or internal site). Applications System Terminal Get your data from your unet account (see Section Data Security ) Decompress your data > tar -xf dateiname.tar Start to work Sylvia Plöckinger () An Introduction to Unix March 3, 2011 4 / 29
Astro Lab How to use the computers in the lab Documentation www.univie.ac.at/astro/internal/lab/ (Unet Login) Close down Compress your data > tar -cvf dateiname.tar directory/ Put your data to your unet account with scp or sftp Quit the terminal with > exit Leave Logout Never shut down the computer! How to use the printer lpr -H <printserver> -P <printername> <filename> Sylvia Plöckinger () An Introduction to Unix March 3, 2011 5 / 29
Astro Lab How to use the lab computer from other maschines 1 Get a terminal (f.e. x11 (mac), cygwin (windows)) 2 Get an IP address within the firewall 3 ssh -Y <UserID>@lab<nr>.astro.univie.ac.at RSA key? Ad 1 (Windows) http://x.cygwin.com Install Cygwin/X now Install from Internet Choose a Server X11 xterm X11 terminal emulator Ad 1 (Mac) /Applications/Utilities/X11 Programme/Dienstprogramme/X11 If it is not there, install it from your Mac OS CD/DVD Sylvia Plöckinger () An Introduction to Unix March 3, 2011 6 / 29
Astro Lab How to use the lab computer from other maschines 1 Get a terminal (f.e. x11 (mac), cygwin (windows)) 2 Get an IP address within the firewall (www.univie.ac.at/zid/vpn) 3 ssh -Y<UserID>@lab<nr>.astro.univie.ac.at RSA key? Ad 2 www.univie.ac.at/zid/vpn Install the VPN Client for your system Connect with your unet accout Sylvia Plöckinger () An Introduction to Unix March 3, 2011 7 / 29
Unix Basics Unix Basics Login: > User-ID <Return> > Password <Return> Do not expect any symbols, when typing in your password! Logout: > exit <Return> or: > logout <Return> Special directories:. current directory.. one level up in the directory path home directory / root directory Different kind of paths: Absolute path (> pwd): /home/numast/mydir Path from home directory: ~/mydir/ Relative path:../mydir/ Sylvia Plöckinger () An Introduction to Unix March 3, 2011 8 / 29
Unix Basics Unix Commands In general > <command> [option(s)] <argument> Command examples Make Directory > mkdir newdir Exercise: What s the difference? > mkdir newdir/subdir/subdir2/ > mkdir -p newdir/subdir/subdir2/ > mkdir -vp newdir/subdir/subdir2/ Change directory > cd newdir > cd.. > cd../newdir > cd ~/newdir Sylvia Plöckinger () An Introduction to Unix March 3, 2011 9 / 29
Unix Basics Unix Commands Command examples List > ls [-la -h] > ls [-la -h] *.txt > ls [-la -h] /home/ Case sensitive! Copy a file > cp newfile.txt../newdir/. Move / rename a file > mv newfile.txt../newfile2.txt Remove a file or directory > rm newfile.txt > rm -r newdir removes newdir with all files and subdirectories > rm -rv newdir > rmdir newdir removes only empty directories Be very careful! No messages like: Are you sure? <Return> Really?. No recycle bin! Be even more careful, when using a wildcard * helpful option -i. Sylvia Plöckinger () An Introduction to Unix March 3, 2011 10 / 29
Unix Basics Unix Commands Output in files: > ls -la -h > list.txt >./a.out > output.dat Disk usage (free memory): du [-h -s] df -h df -h /home Output page by page: > ls -la -h more > more test.dat Search for...... files: > locate newfile.dat... commands: > whereis ls... within files: > grep [-i -l -v] atest *.dat... yourself: > whoami Learn more about every command: > man <command> (quit man with q ) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 11 / 29
Unix Basics Emergency Exit Kill Jobs Foreground jobs: [Ctrl] + c Get your process ID: > top (quit top with q ) > kill <PID> > kill -9 <PID> Contact us or Mr. Fischer (system administrator) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 12 / 29
Editors The Vi Editor Start Vi: > vi > vi newfile.dat Start insert mode a or i Quit insert mode [Esc] Delete [Esc] x current character [Esc] dd current line Go to line nr. <nr> [Esc] :<nr> Go to the last line [Esc] G Copy a line [Esc] Y Paste the copied line [Esc] P Save file: [Esc] :w [Esc] :w newfile2.dat Save file and quit vi: [Esc] ZZ [Esc] :wq [Esc] :x Quit Vi without saving: [Esc] :q [Esc] :q! Sylvia Plöckinger () An Introduction to Unix March 3, 2011 13 / 29
Editors Vi - A brief instruction (www.fehcom.de/pub/viref.pdf) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 14 / 29
Editors Vi - A brief instruction (www.fehcom.de/pub/viref.pdf) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 15 / 29
Editors The Emacs Editor Start Emacs: > emacs > emacs newfile.dat Open file in buffer [Ctrl]-x [Ctrl]-s Go to beginning of line [Ctrl]-a Go to end of line [Ctrl]-e Save file: [Ctrl]-x [Ctrl]-s Quit Emacs: [Ctrl]-x [Ctrl]-c Sylvia Plöckinger () An Introduction to Unix March 3, 2011 16 / 29
Editors The XEmacs Editor Start Emacs: > xemacs > xemacs newfile.dat & Advantage: Very user-friendly Nice GUI - with lots of buttons to click on Sylvia Plöckinger () An Introduction to Unix March 3, 2011 17 / 29
Data Security (unet) Data Security Do not use the lab computers to store your data! Use your unet filespace! Sylvia Plöckinger () An Introduction to Unix March 3, 2011 18 / 29
Data Security (unet) How to use the unet filespace Login ssh -Y a<matrikelnr.>@unet.univie.ac.at Unet password Type in s to use the Unix shell Logout Type > exit to quit the shell Type q to close the unet-connection Secure Copy Copy files from lab1-12 to unet with secure copy (scp) instead of cp. scp <UserID>@lab<nr>.astro.univie.ac.at:Numast/testing.dat Numast/. From unet to lab1-12: scp testing.dat <UserID>@lab<nr>.astro.univie.ac.at:Numast/. Sylvia Plöckinger () An Introduction to Unix March 3, 2011 19 / 29
Data Security (unet) How to use the unet filespace SSH File Transfer Protocol (SFTP) Example: You are logged in on one of the lab machines and want to put/get data on/from your unet account: > sftp a<matrikelnr.>@unet.univie.ac.at > put Numast/testfile.dat > get testfile.dat > exit Question: What is the target/source directory? Local directory (ssh -Y <UserID>@lab<nr>.astro...) lls lcd lpwd lmkdir Remote directory (sftp a<mnr.>@unet.univie.ac.at) ls cd pwd mkdir Sylvia Plöckinger () An Introduction to Unix March 3, 2011 20 / 29
Tips for lazy users Tips for lazy users Command completion: [Tab] or [Tab] [Tab] Search the shell history: [Ctrl] + r (quit the search with [Esc]) Create your own commands in the ~/.bashrc: > vi ~/.bashrc alias l="ls -la -h" alias..="cd.." alias...="cd../.." alias rm="rm -i" alias myfolder="cd /folder1/folder2/folder3/myfolder/" Look at your alias with > alias Do not remove any other line from the.bashrc! Sylvia Plöckinger () An Introduction to Unix March 3, 2011 21 / 29
Fortran - Part I Very, very basic Fortran 90 Program Structure PROGRAM <program-name> IMPLICIT NONE [declaration part] [execution part] Run the program > vi myprogram.f90 > gfortran myprogram.f90 Find a file a.out in your current directory >./a.out END PROGRAM <program-name> Sylvia Plöckinger () An Introduction to Unix March 3, 2011 22 / 29
Fortran - Part I A Fortran90 variable name (identifier) has less than 31 characters can consist of letters, digits or underscores, (first one must be a letter) is case insensitive (name = Name = NAME = NaMe) Variable Types: Integer 1000, -359, 0, 97338 Double Precision (F77) 1.89d0, 1985.d0, 5,44d7, -2.978d-15 Complex (2.887,-3.654) Real 2.384, -7.0987, 1.67e-8, -186.e3 Logical.true.,.false. Character test, hello, Sylvia Plöckinger () An Introduction to Unix March 3, 2011 23 / 29
Fortran - Part I Variable Declaration Declaration Part - Example Program Structure PROGRAM <program-name> IMPLICIT NONE [declaration part] [execution part] END PROGRAM <program-name> integer (kind=4) :: i, j, k, count (F90) real (kind=8) :: a, b, x (F90) logical :: hello =.true. character (len=11) :: message = "hello world" double precision :: dp1 (F77) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 24 / 29
Fortran - Part I Execution Part Mathematical Operators Arithmetic ** * / + Relational < <= > >= == = / (F90).lt..le..gt..gt..eq..ne. (F77) Logical.not..and..or..eqv..neqv. Function Result Function Result ABS(x) absolute value ASIN(x) arc sine of x SQRT(x) square root ACOS(x) arc cosine of x SIN(x) sine of x (radian) ATAN(x) arc tangent of x COS(x) cosine of x (radian) EXP(x) e x TAN(x) tangent of x (radian) LOG(x) logarithm of x (e) LOG10(x) logarithm of x (10) Sylvia Plöckinger () An Introduction to Unix March 3, 2011 25 / 29
Fortran - Part I Execution Part Read Purpose: Read data from keyboard or file Use: read(<unit>, <format>) <var> read (*,*) a, b, c Write Purpose: Write data on the screen or in a file Use: write(<unit>, <format>) <var> write (*,*) a, b, c Every read (*,*) or write (*,*) starts a new line! <unit> stands for a number between 1 and 99 and has to be unique within the programme Sylvia Plöckinger () An Introduction to Unix March 3, 2011 26 / 29
Fortran - Part I Write data to file Open the file: open (<unit>, file ="dir/ filename", status = "unknown") Write data: write (<unit>, <format>) var1, var2 Close file: close (<unit>) <status> : NEW, OLD, SCRATCH or UNKNOWN <format> : statement label (100-999) write (*,100)a, b, c, d 100 format (E12.4,1X,F8.4,1X,1P,I8.7) a string that contains the format information character (len=40) :: str = "(E12.4,1X,F8.4,1X,1P,I8.7)" write (*,str)a, b, c, d the format statement itself write (*,"(E12.4,1X,F8.4,1X,1P,I8.7)")a, b, c, d Sylvia Plöckinger () An Introduction to Unix March 3, 2011 27 / 29
Fortran - Part I Do Loops in a Nutshell DO x = 1, 10, 2 f x = x*x + 10. write (*,*) x, f x ENDDO x=1 DO f x = x*x + 10. write (*,*) x, f x IF (x > 10) EXIT x = x+2 ENDDO Sylvia Plöckinger () An Introduction to Unix March 3, 2011 28 / 29
Fortran - Part I Get started! Sylvia Plöckinger () An Introduction to Unix March 3, 2011 29 / 29