620 likes | 740 Views
Linux. Joe Meehean. How do I…?. Log in Do basic stuff Use the file system Access my files from Windows Edit files Do C++ development Hand in my programs. Why are we using Linux, really?. Linux is wide spread smartphones (Android): 64% worldwide web servers: >60%
E N D
Linux Joe Meehean
How do I…? • Log in • Do basic stuff • Use the file system • Access my files from Windows • Edit files • Do C++ development • Hand in my programs
Why are we using Linux, really? • Linux is wide spread • smartphones (Android): 64% worldwide • web servers: >60% • servers (general) : ~13% • animation/visual effects: 95% • Learning Linux allows you to learn other OS’s quickly • Solaris • OS X (low-level)
Why are we using Linux, really? • Awful Windows C++ development tools • compiler inaccurate/misleading • compiler not to spec • limited support for Boost libraries • debugger also inaccurate/misleading
How to I log in? • Remotely • Using a tool called FreeNX • like remote desktop but from Windows to Linux • What do I need to know? • Linux server name: mintaka.lynchburg.edu • your username & password on mintaka
Linux Desktop • I thought Linux was text-based • we’ll use KDE • a graphical user interface on top of Linux OS • can use a mouse, windows, etc… • KDE is nice, but… • at its heart Linux is text-based • people used to log in remotely using special dumb terminals • we’ll use the text-based interface too
How to I log in? • Remotely • Using a tool called Putty • like Windows cmd, but connects to machine across network • What do I need to know? • Linux server name: mintaka.lynchburg.edu • your username & password on mintaka
The Shell The text-based interface to Linux
The Shell • The shell is • where users type commands • see results of those commands
The Shell • Example commands • date: prints the date and time • who: prints who else is logged in • top: shows resource usage • like Windows Task Manager • man <cmd>: shows a manual for command cmd • e.g., man date • grep <word> [file]: search for a word or phrase in input or a file
The Shell meehean_j@mintaka:~$ ps PID TTY TIME CMD 8578 pts/0 00:00:00 zsh 8630 pts/0 00:00:00 bash 8688 pts/0 00:00:00 sleep 8689 pts/0 00:00:00 ps meehean_j@mintaka:~$ kill 8688 meehean_j@mintaka:~$ ps PID TTY TIME CMD 8578 pts/0 00:00:00 zsh 8630 pts/0 00:00:00 bash 8690 pts/0 00:00:00 ps • Example commands • ps: prints commands you are currently running • kill <pid>: terminates the process with id pid • e.g.,
The Shell • Can run commands in two modes: • Foreground • shells assumes command is interactive • user cannot run another command until foreground command finishes • default mode
The Shell • Can run commands in two modes: • Background • shell assumes command is not interactive • shell starts command, doesn’t wait for it to finish • command output will still be printed to screen • command must be followed by & to put into background
The Shell • Interacting with commands while running • Ctl-C: kills foreground command • Ctl-Z: suspends foreground command • fg: run background command in foreground • bg: run suspended command in background
The Shell • Chaining commands together • cmd1 ; cmd2 ; cmd3 • run cmd1, then cmd2, then cmd3 • cmd1 | cmd2 | cmd3 • run cmd1 • run cmd2 using output of cmd1 as input • run cmd3 using output of cmd2 as input • e.g., who | grepmeehean_j
The Shell • File input/output • cmd > out.txt • run cmd and store its output in out.txt • does not print output to screen • e.g., who > users.txt • cmd < in.txt • run cmd and use in.txt as its input • grepmeehean_j < users.txt
The Shell • The wildcard: * • it means match 0 or more characters • e.g., who | grep m* • prints all logged in users whose name starts with m • e.g, who | grep *m* • prints all logged in users whose name has an m in it
The Shell • Like everything in Linux the shell is really just a program • Many different options • bash (the default) • tcsh • zsh • In KDE, need a visual display for the shell • a terminal emulator • called Konsole
How do I…? • Log in • Do basic stuff • Use the file system • Access my files from Windows • Edit files • Do C++ development • Hand in my programs
The File System • Root directory • top of the file system • located at / • Each user gets a directory (folder) • called the home directory • located at: /home/<username> • Current working directory (cwd) • where your shell will look for files • can change your current working directory
The File System • Directory name shortcuts • / : root • ~ : your home directory • ./ : your current working directory • ../ : the directory one up from the cwd • ../../ : the directory above ../ • Hidden files • start with a ‘.’
The File System • commands • pwd: print working directory • ls: list the contents of the cwd • ls • ls *.txt : list all files that end in .txt • ls –a : list hidden files too • ls <directory>: list the contents of <directory> • ls /tmp: list all files in /tmp • cd <directory>: change cwd to <directory> • cd ../ : move up one directory • cd /tmp : move to the temporary directory
The File System • commands • touch <filename>: make a file called <filename> • touch test.txt : make a file called test.txt in cwd • touch /tmp/a.wav : make a wav file in /tmp • rm <file> : remove (delete) <file> • rm test.txt : remove file test.txt in cwd • rm /tmp/a.wav : remove the file a.wav from /tmp • rm *.cpp: remove all files that end in .cpp
The File System • commands • mkdir<dirname>: make a directorycalled <dirname> • mkdir cs242 : make directory called CS242 in the cwd • mkdir ~/cs242 : make cs242 directory in home dir • rmdir <dir> : remove directory <dir> • <dir> must be empty • rmdir cs242 : remove directory cs242 from cwd • rmdir ~/cs242 : remove directory cs242 from home • rm –r <dir>: remove directory <dir> • <dir> doesn’t need to be empty
The File System • commands • cp <file1> <file2> : make a copy of <file1> called <file2> • cp a.cpp a.cpp.bkup : create a copy of a.cpp called a.cpp.bkup • mv <file1> <file2> : rename/move <file1> to <file2> • mv a.cpp b.cpp : change a.cpp to b.cpp • mv a.cpp.bkup a.cpp : overwrite a.cpp with a.cpp.bkup
The File System • commands • cat <file> : print file contents to screen • cat a.cpp : print a.cpp to screen • less <file> : open file using file reader less • less a.cpp : read a.cpp using less • use arrows to move around • use q to quit
Samba • Network file service for Linux • maps your home directory in Windows • Preparation • have system admin add you as samba user • log in to mintaka • set your samba password
Samba • Mapping mintaka home directory in Windows • right click on Computer • select “map network drive” • folder: \\mintaka\<your_linux_username> • select log in as different user • user: \<your_linux_username> • password: <your_linux_password>
How do I…? • Log in • Do basic stuff • Use the file system • Access my files from Windows • Edit files • Do C++ development • Hand in my programs
Emacs • Simple extensible editor • can edit several different languages • can run the debugger • can read your email • can do everything really
Emacs • Terminology • buffer: an open file • kill: cut • yank: paste • point: cursor • mark: a user-specified location • e.g., kill from point to mark • region: text between point and mark • window: emacs can be split into different buffers open at the same time
Emacs • Starting it up • > emacs • Emacs documentation abbreviations • Esc = M • Ctrl = C (called command) • Commands in emacs • C-x C-f: open a file • C-x C-s: save the current buffer to its file • C-x C-c: close and exit
Emacs • Search and replace • C-s: search forward • C-s fool : move point to next fool after point • C-r: seach backward • C-s fool : move point to previous fool before point • M-% : find and replace • interactive • directions provided on screen
Emacs • Kill and yank • cut and paste • C-k : kill to end of line • cut from point to end of line • C-y : yank back last thing killed • paste at point • C-w : kill region • multiple sequential kills are yanked back with one yank
Emacs • Windows • C-x 2: split into two windows, above and below • C-x 3: split window, side-by-side • C-x 0: delete this window (unsplit) • C-x 1: delete all other windows beside this one • C-x o: move to another window • Buffers • C-x b: select another buffer (open file) • C-x C-b: select another buffer (from list)
Vi • Editor runs in terminal • cannot use the mouse • Two modes • command mode • for entering commands • text entry mode • for inserting text into file • Starting up • > vi file_to_edit
Vi • Working with files <command mode> • :e file = open file • :w = save file • :q! = quit without saving changes • :x = save changes and quit • Inserting text • a = switch to text entry mode after cursor • i= switch to text entry mode before cursor • Esc = switch back to command mode
Vi • Search <command mode> • /word: seach for word • n: search for next appearance of word • N: search for previous appearance of word
Vi • Replace <command mode> • :rs/foo/bar/a: replace foo with bar • r is range, can be • nothing: works only on current line • number: works only on line number • % : whole file • a is argument, can be any combo of: • g: replace all occurrences in line, not just first • i,I: ignore case, don’t ignore case • c: confirm each replace • :%s/teem/team/gi
Vi • Cut/Copy/Past/Undo <command mode> • x: cut current character • dd: cut line • Xdd: cut X lines • 5dd • D: cut to end of line • yy: copy line • p: paste • u: undo
How do I…? • Log in • Do basic stuff • Use the file system • Access my files from Windows • Edit files • Do C++ development • Hand in my programs
Compiling by Hand • C++ compilation demystified • compile source files into binary object files • i.e., .cpp into .o • link together multiple object files into a program • i.e., combine multiple .o files into an executable
Compiling by Hand • g++ is the Linux compiler for C++ • -c compile • e.g., g++ -c file1.cpp file2.cpp file3.cpp • -o link • e.g., g++ file1.o file2.o file3.o –o executable • Useful options for g++ • -g: include debugging information • -Wall: print out any warnings