General Remarks on the Operating System UNIX/Linux
Total Page:16
File Type:pdf, Size:1020Kb
Contents: 1 General remarks on the operating system UNIX/Linux 2 First steps at the computer 3 File systems 4 Editing and printing text files The operating system Linux More important commands 5 UNIX-shells and programming languages 6 Process administration 7 The programming language C++ - an overview An introduction 8 Fortran 90/95 - an overview 9 Creating executable programs Joachim Puls and Michael Wegner Additional material • vi basics: vi brief.pdf • reference for vi: vi reference.pdf • reference for emacs: emacs reference.pdf Acknowledgements. Many thanks to Tadziu Hoff- mann for carefully reading the manuscript and useful comments. c 2010, Joachim Puls & Michael Wegner (1st ed.) 1 General remarks on the operat- Essential features ing system UNIX/Linux UNIX • has been originally written in the programming Classification of UNIX/Linux language C, and is therefore a classical platform for C-programs. UNIX contains well suited en- UNIX is a Multi-User/Multi-Tasking operating system vironments for program development (C, C++, and exists in many different versions (“derivates”): Java, Fortran, ...). Solaris, AIX, XENIX, HP-UX, SINIX, Linux. • is mainly used for scientific-technical applications on mainframes and workstations, but has be- User come, because of Linux, also popular for classical PC-applications throughout the last years. • is perfectly suited for application in networks. Larger systems and networks require an admin- istrator. • offers various alternatives for the solution of most tasks. The multitude of commands (more than in any other OS) are brief and flexible. Hardware • is originally command-line oriented, but can be used via a graphical user interface (X Window system). Operating system Linux is available (also via internet) in different dis- application programs tributions (S.u.S.E., Fedora, Debian etc.). Mean- while there is a variety of direct-start (live) systems, which can be started, without installation, directly from CD or other bootable storage devices (Knop- Operating system (OS): Sum of all programs which pix, Ubuntu, ...). There are also interesting “mini are required to operate a computer and which control versions” (<100 MB) designed for a start from USB- and monitor the application programs. sticks (e.g., Puppy). The source code of Linux is free. 1 2 Literature 2 First steps at the computer • Peek, J., et al.: Unix Power Tools. User, logon, logoff O’Reilly Media 2002 (3rd edition). Since UNIX is a multi-user operating system, it can deal with several users simultaneously. Each user • Gilly, D., et al.: UNIX in a Nutshell. needs a user account. O’Reilly, K¨oln. 1998 (1st edition). Each user has a personal environment (home di- rectory, shell), which can be accessed only by her- • Wielsch,M.: Das große Buch zu UNIX. /himself (and by the system adminstrator and those Data Becker, D¨usseldorf. 1994 (1st edition). people who know the password – legitimate or by hacking). Inside the system the user is identified by his user ID • and numerous other text books (UID) and his group identity (group ID, GID). • online-tutorial There are two user types: http://www.ee.surrey.ac.uk/Teaching/Unix • ‘normal’ users with restricted rights and the • system administrator (root) with all privileges. The latter is responsible for the installation, con- figuration and maintenance of the system as well as the user administration. Each user has to logon and to logoff from the system (login/logout). Each user account is protected by a password. Exercise: Login to the system with your user account! 3 4 Graphical user interface command xterm Originally, UNIX is command-line oriented. The X Window system enables convenient interaction via a Syntax: window-oriented graphical interface, similar to other OS. xterm [options] The window manager is responsible for the manage- Though there is a graphical interface, UNIX needs ment and display of the individual windows. Each the possibility for direct command input for practical window manager (and there are a variety of such man- use. Therefore, at least one terminal window needs agers) can be distinguished by its own Look and Feel to be open. This can be accomplished via the window (appearance of window decorations and control de- manager or the desktop environment (‘console’) vices etc.). Most window managers can be choosen at the login-menu. More windows can then be opened with the command xterm. Examples for simple window managers: Generally, all UNIX commands have a variety of op- • twm: very simple and resource-saving tions, which usually begin with -. For the commands which will be introduced in the following, we will pro- • mwm: Motif window manager, more common and vide only the most important ones. more advanced Example: • xfce: convenient, simple, and resource-saving (recommended for use in virtual machines) wegner@arber:~ > xterm -geo 80x40 -fn 10x20 The command xterm is called with two options -geo, Moreover, almost all Linux distributions provide -fn, which, in this case, need additional arguments graphical desktop environments such as KDE or (width and height of window, font name & size). GNOME, which have a functionality far beyond simple window managers. Exercise: 1. Open a terminal window (“terminal program”) via KDE. 2. From there, start another xterm! 5 6 command man command passwd Syntax: Syntax: man command passwd man -k expression sets a new password. displays the manual pages (“man pages”) for the pro- Passwords should be constructed from a combination vided command. man -k searches for man pages contain- of letters, digits and special characters, and should ing the expression in the NAME section. A man page not appear in any dictionary or similar list. Otherwise, usually consists of the following sections the password can be hacked by systematic search al- gorithms. • NAME command and purpose The command to set/change the password and • SYNOPSIS syntax of command the required conventions (length, number of dig- its/letters/special characters) can vary from system to system. The following example is a common one, • DESCRIPTION of command effect e.g., valid for the workstations at the CIP Pool (but not for the workstations of the USM). • FILES which are modified and/or needed Example: • OPTIONS if present wegner@arber:~ > passwd • EXAMPLE(S) for application (rarely) Changing password for wegner Old password: myoldpasswd • BUGS errors, if known Enter the new password (minimum of 5, maximum of 8 characters) • SEE ALSO other commands in the same context Please use a combination of upper and lower case letters and numbers. New password: mynewpasswd Exercise: Re-enter new password: mynewpasswd Display information about the command xterm! Password changed. 7 8 Example: command who, whoami ----> Ihr neues Passwort ist in 5 Minuten Syntax: im gesamten Pool aktiv! <----- Connection to 141.84.136.1 closed. wegner@arber:~ > who whoami who displays information about all users which are logged into the system • user name, • terminal where the corresponding user is working, • time of login. whoami is self-explanatory. Example: wegner@arber:~ > whoami arber!wegner pts/5 Oct 20 12:45 9 10 Working at external terminals OR (if connection within “own” cluster) To login to a distant host, one has to provide the corresponding IP address, either numerical or as the Example: complete host name name.domain. In local networks (CIP-Pool), the brief host name (without domain) is wegner@arber:~ > ssh -X wegner@arber sufficient. To establish the connection and to encrypt Last login: Sun Oct 22 ... the transmitted data, one should use exclusively the etc. (keine Passwort-Abfrage) so-called “secure” commands. Avoid ftp and use sftp instead. With ftp, even the password is not encoded! An additional advantage of the secure shell is that command ssh the distant host hostname can display X applications on the local terminal, without requiring the command xhost (as in earlier times). For certain hosts, the com- Syntax: mand ssh requires the option -X to enable this feature. ssh (-4) -X -l username hostname ssh (-4) -X username@hostname Enables logging in to an arbitrary host which can be located via an IP address (if one knows the user ac- count and the password). Logoff with exit, Ctrl-D or command scp logout. In case, the option -4 (without brackets) forces an To copy files from one host to another, the command IPv4 connection (if IPv6 is not working) scp (“secure copy”) is used, see also cp. Example: Syntax: wegner@arber:~ > ssh -X -l wegner lxsrv1.lrz-muenchen.de Password: mypasswd scp (-4) file1 username@hostname:file2 Last login: Sun Oct 22 ... scp (-4) username@hostname:file1 file2 ********************* Mitteilungen The first command copies the local file file1 to the ********************* external host under name file2, the second command wegner@lxsrv1:~ > logout vice versa. Note the colon! scp -r enables to copy Connection to lxsrv1.lrz-muenchen.de closed. complete directories recursively, compare cp -r. 11 12 3 File systems Avoid characters which might be interpreted by the shell in a special way. Logics, file types A file can be referenced within the file tree by either “In UNIX everything is a file.” an absolute or a relative path name. An absolute path name consists of all directories leading to the file and The following file-system objects can be found the file name, and always begins with a / (the root directory). • ‘normal’ (text-) files In many shells and application programs, the tilde de- • executable files (binary files or shell scripts) notes the home directory. • directories • device files • pipes command pwd • symbolic or hard links (references to files) Syntax: All files and file system objects are ordered within a hierarchical file tree with exactly one root directory pwd ‘/’. displays the current directory. In contrast to the MS-Windows file system, the UNIX file system does not distinguish between dif- Example: ferent drives. All physical devices (hard disks, DVD, CDROM, USB, floppy) are denoted by specific files inside a certain directory within the file tree (usually wegner@arber:~ > pwd within /dev).