A Very Short Introduction to Linux Kyrre Ness Sjøbæk University of Oslo, FYS3150 10th of September, 2009 This talk, and related files, may be found at http://folk.uio.no/kyrrens -> Nyheter -> Linuxkurs There is a short compendium about the terminal! Intended Audience: People who have never really used Linux before People who have a little experience with Linux, and want to work efficiently Outline General stuff How to setup and use the file explorer Tips and tricks with the graphical environment Some Firefox tricks The Terminal at a glance Basic commands TAB completion Emacs – it isn't dangerous Important keybindings Tips & tricks General stuff – Use of the file manager “Nautilus” (I) Default behavior: Open a new folder = Open a new window To change it: Open a folder, hit edit -> preferences -> behavior -> Always open in browser window Previews of pictures etc. may be turned on in the same dialog General stuff – Use of the file manager “Nautilus” (II) Sometimes you want to change the default program used to open a file type You may choose Example 1: Mostly you just want to view an image, but sometimes you want to edit (Gimp) Example 2: .eps files have a really bad default program to open it. Set it to “Document viewer” (evince) Right-click a file of the interesting type You may here choose another program only once Click “preferences -> Open with” to change default General stuff – Tips and tricks with the graphical environment (I) You have “multiple desktops” These act as extra screens Use the mouse on the onscreen control, or keyboard shortcuts Tips: Use one desktop for code, one for a terminal, one or two for report writing, one for web... Keyboard shortcuts: Move around (change active desktop): Control-alt-<arrow> Move around, and drag a window with you: control-alt-shift-<arrow> General stuff – Tips and tricks with the graphical environment (II) Very useful: Know how hard your computer is working To get it: Right click top or bottom panel, “Add to panel” Choose “System Monitor” Right-click the thing that pops up -> properties -> check at least “CPU” and “Memory” Harddrive activity Network activity Memory: Dark green means “in use by a program”. Ligth green means that its used to get files faster. Watch the dark green! CPU: Blue means “in use”. Note: On a dual core, 50% means that one core is working max, other is sleeping. (similarly for quad) A few tips & tricks with Firefox Useful keyboard shortcuts: Control-L : Activate address bar Control-K : Activate search bar Control-T : Make new tab, activate address bar Control-click or mousewheel-click : Open link in new tab Control-F : Search in page Making a “quicksearch”: Right-click on a search field, select “Make keyword for this search”. Pick a name and a keyword Examples: Wikipedia as “wp”, UiO person-search as “uiop” ... To use: type “<keyword> <searchterm>” in the address bar The terminal at a glance In the terminal: Use “commands” to make things happen A command is a special word (technically: the name of the program which does it) followed by a set of “arguments” – for example: mv -R oldplace newplace Note that commands are case sensitive: UPPERCASE ≠ lowercase The terminal at a glance – Important commands (I) Moving around in directories : Listing directory content cd <newdir> : Change working directory pwd : Print name of current working directory mkdir <newdir> : Making a new directory ls (-la) Copying and moving files cp (-r) <file> <copy> : Copying a file mv <file> <newname> : Moving / renaming a file The terminal at a glance – Important commands (II) Creating and deleting files, looking inside them: cat <filename> : Print the content of a textfile in the terminal touch <filename> : Create a new, empty file rm (-rf) <filename> : Delete file or directory Controlling programs Control-C : Stopping the active program, aborting input Control-X : Pausing the active program bg : Unpause the active program, and put it in the background <command> & : Start a program/command, and put it in the background The terminal at a glance – Important commands (III) What programs are running, and how to stop them: top : Display a list of what programs are active and consuming resources (“q” to quit) ps aux : Display a list of all running programs ps aux | grep <name> : As above, but only display lines containing <name> killall (-9) <name> : Kill the program named <name> kill (-9) <PID> : Kill the program with process ID <PID> xkill : Gives you a crosshair to kill programs... The terminal at a glance – TAB completion Avoid writing long command- and file names: Use the “TAB” key To do it: Start writing a command/filename, and when you have entered the first 2-3 letters, try hitting “TAB”. If it is unambiguous (no other command/filename starting with the same letters), the terminal will fill in the rest. If it is ambigious, try 1-2 more letters, and hit tab Hitting tab twice (when there are ambiguities) brings up a list of possibilities. The terminal at a glance – screen (I) If you have a long job, you can start it within a “screen” This gives you a new “terminal”, independent of the physical display/keyboard in front of you. You can “detach” and later “reattach” to this terminal. You may, for example, start a long job in screen, detach and log of the computer, go home, eat dinner/whatever, and later ssh the computer, reattaching to check progress etc. The terminal at a glance – screen (II) Important commands: screen : Starting a new screen control-A-D : Detach from a screen screen -r : Reattach to a running screen Emacs – it isn't dangerous One of the best editors for pure text – especially programming (“kate” is also good) In development since the 70's (1984: GNU emacs) Has an enormous amount of features, scriptable (LISP) Can do syntax highlighting for almost any language While emacs has a steep learning curve – it is worth it To start emacs: emacs <filename> Emacs – Important concepts Important concept in emacs: Buffer – A piece of text (an open file, a dialog, a command line etc.) Window – Where the buffers are displayed Most commands in emacs is made with holding control (C) or alt (Meta) while typing something “Space cadet” keyboard: Seven (7!) modifiers, used as “chords” with the left hand. Modern PC keyboards: 5 Control, Alt, Shift, AltGr, Super (windows-key). Some laptops also have an extra “Fn” key. Worse placement of modifiers on PC Emacs – Important keybindings (I) Saving files, closing emacs, etc. C-x-s : Save current buffer C-x-c : Close emacs C-x-f : Find (open) file C-_ : Undo (to type “_” (underscore): Shift+”-”) Searching in the text: C-s : Search in current buffer M-% : Search and replace in current buffer Emacs – Important keybindings (II) Marking, copy & paste: M-w : Copy marked area C-w : Cut marked area C-y : Paste C-space : Set mark Meta-x: the “command line” inside emacs. Press “M-x” and type the command. Watch the bottom area (minibuffer). TAB-completion is supported. M-x recover-this-file : Read autosave information (“#filename#” file) (useful if something crashed...) M-x comment-region : Make the marked area a comment Emacs – Important keybindings (III) Making room for more buffers: C-x 2 : Divide current window horizontally C-x 3 : Divide current window vertically C-x 1 : Only show current window C-x o : Switch active window C-x b : Switch which buffer is showing in the current window C-x k : Close (kill) current buffer Note: Hit first C-x and then hit 1,2,3,o,b, or k ! Emacs – hints about the GUI Name of the buffer showed in the window Character map: “-1” = Latin1 (ISO-blahblah) “-u” = UF8 Two stars “**”: Unsaved file Which line is the marker on? Minibuffer – Emacs writes status messages, asks for input etc. here. Watch it! Currently using “Text” edit mode (for syntax highlighting etc.) may also be C++, LaTeX, ...) Questions?