A451 - Stellar Astrophysics - Introduction to Linux Most astronomers using PC computers use the Linux operating system for data reduction and analysis. While not (quite) as user friendly as Windows, Linux offers the user more "hands on" control of what the computer is doing, and much of the software that astronomers need runs under Linux. We will use Linux computers for A451. This guide is designed to help you become familiar with the Linux operating system and make the transition from Windows to Linux. Many of the basic functions of Windows (word processing, spreadsheets, browsers, etc.) are also available under Linux, and many of them operate in the same basic way. Technically, Linux refers to the operating system and/or its philosophy. The user interface in Linux is called a shell because it separates you from the inner guts of the system. Mostly, the shell just runs the programs you tell it to run. Almost all the commands you will use are just regular programs -- the shell doesn't care if it's a program you wrote or one that came with the system. We carry out tasks on Linux computers using two different types of interfaces. These are the text based interface and the graphical interface. Each has advantages and disadvantages. You should choose the interface most suitable to the job you need to do. The command line interface is more suited to complex tasks where presenting the work visually is impractical. On the other hand, the graphical interface works well for problems that are strongly visual or can be presented in a menu format. In this class, you will need to be able to work with both interfaces. We will use the Gnome graphical interface. It is one of several choices available, but all are rather similar and if you are familiar with one you will be able to find your way around the others. Logging in and out To login in, type: your username Enter the password: (nothing will appear as you type this) On a Linux workstation, you will need to start the window system after you log in. The window system has two modes: a high resolution mode and a low resolution mode. Most of the time you will want the high resolution mode, so you should type startx In the top left corner of the screen you will find icons for your home directory and the trashcan. Double click on the home directory icon to see the contents of your home directory or other directories in graphical format. Files that you remove using the graphical interface tool will appear in the trashcan. Remember that files you remove while using the shell are gone forever and will not appear in the trashcan – you should be very careful about deleting files. In the bottom left corner, you will find buttons for accessing applications. The buttons are: A red hat, which gives you access to the program menu. This is similar to the Windows Start Menu. A globe with a computer mouse, which starts the Mozilla web browser A notepad and pencil, which starts the GEdit text editor A computer screen, which provides opens an XGTerm terminal window A magnifying glass, which opens ds9, a tool to display astronomical images A piechart and ledger, which opens the Gnumeric spreadsheet application When you are ready to log out, click on the red hat, then choose “Log Out”. A window will pop up to confirm that you want to log out. Choose “OK”. You will be returned to the terminal. Type logout to log out from the terminal. The login prompt will appear again. Always remember to log out completely when you are finished! Command Line Window Applications In the graphical interface, you can run a program by pressing ALT+F2. A dialog box will appear, and you may type the command you would like to run. You may also use a shell terminal such as XGTerm or XTerm. These applications will provide you with a terminal inside a window. The button at the bottom left corner of the screen allows you to open XGTerm, or you can type “xterm” or “xgterm” into the run dialog. You can also run XTerm from the program menu. In XGTerm, the font size should be set to “huge” by default. If you prefer a different size, you can change it by pressing and holding control and clicking the middle mouse button. When you do this, a menu will appear offering you a choice of sizes. You can use the XTerm and XGTerm in just the way you would if you weren’t using the windowing system, and you can also run graphical applications from an XTerm or XGTerm window. When you run a graphical application this way, it’s usually a good idea to run the program “in the background” so that you can continue to use the terminal window. To run a program in the background, type an ampersand (&) after the command. For example, xterm & Directories Linux "folders" are called directories. The top-level, root directory is called /. Your home directory is /home/username. From anywhere you can get back there by typing simply cd The short-hand name for the directory you happen to be in at any time is called "." and the directory in which the current directory resides is called "..". Typing "cd .." will move you to the next higher level directory. Several useful commands for directories are listed below. Command cd pwd mkdir rmdir ls Function Change directory Print working directory Make a new subdirectory Remove a directory List files in a directory Examples cd, cd .., cd /home/catyp pwd mkdir newdirectory rmdir emptydirectory ls, ls –l Files: Files reside in directories. Use the ls command (or ls -l for more information) to see all the files in a directory. Useful commands for manipulating files include: Command ls mv cp Function List files Rename (move) a file Copy a file rm Delete (remove) a file cat Output the contents of a file to the screen Identify the type of file file Examples ls, ls -l, ls dirname mv oldname newname cp oldname newname cp oldname dirname/ rm filename rm file1 file2 file3 rm -r dirname cat filename file filename Editing Files You will frequently need to edit text files when you are working in Linux. There are a number of editors to choose from. You can open the editor simply by typing its name on the command prompt. When working in the windowing system, you can use GEdit, a simple graphical editor. To use GEdit, type gedit & at the command line or click the notepad icon at the bottom left corner of the screen. A window will appear with an interface similar to Windows Notepad. Open and save your work using the buttons above the command line. You can also type gedit filename & to open a file in GEdit. Many other editors are available, including EMACS, Pico, and vi, that are sometimes useful in other applications. Documentation for these editors is available in room 311. Printing You can send a plain text file, a postscript format file, or a PDF file to the printer by typing lpr filename To print other types of files, you will need to view them with the appropriate application and print them from there. Shortcuts Cutting and Pasting: In the windowing system and on the text interface, it is possible to cut and paste text. First, select the text with the mouse. Once you select the text, it will automatically be copied to the clipboard. You can now paste the text elsewhere by clicking the middle mouse button. A duplicate of the text will now appear at the text cursor position. Some Linux applications also have a Windows style clipboard available. To copy to this clipboard, press CTRL+C. Then, select your paste location and press CTRL+V. Wildcards: If you need to refer to a list of multiple files, you can use wildcards. These are characters that have a special meaning to the shell. The two most important wildcards are the asterisk (*) and question mark (?). An asterisk will match any string of zero or more characters in a file name, while the question mark will match any single character in a file name. For example: The pattern… f* *.txt f?.txt *.* Will match… f1, f2, f3, fruit.txt somefile.txt, pasta.txt f1.txt, f2.txt, fz.txt fruit.txt, pasta.txt, pasta.txt.bak But not… somefile.txt, 1f pasta.txt.bak, somefile f1, f1.txt.bak, f.txt f1, somefile Linux "help" If you don’t know how to do something, Linux has a built-in help system that you can use. The most important tools are listed below. man command apropos keyword whatis command Display the manual page for a command. Print a list of commands apropos to a keyword with a one-line explanation for each command. Print the one-line explanation for a command.