+ All Categories

Linux

Date post: 04-Feb-2016
Category:
Upload: eytan
View: 37 times
Download: 0 times
Share this document with a friend
Description:
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% - PowerPoint PPT Presentation
Popular Tags:
59
Linux 1 Joe Meehean
Transcript

CS242 Data Structures II

Linux1Joe Meehean

How do I?Log inDo basic stuffUse the file systemAccess my files from WindowsEdit filesDo C++ developmentHand in my programs

2Why are we using Linux, really?Linux is wide spreadsmartphones (Android): 64% worldwideweb servers: >60%servers (general) : ~13%animation/visual effects: 95%Learning Linux allows you to learn other OSs quicklySolarisOS X (low-level)3Why are we using Linux, really?Awful Windows C++ development toolscompiler inaccurate/misleadingcompiler not to speclimited support for Boost librariesdebugger also inaccurate/misleading4How to I log in?RemotelyUsing a tool called FreeNXlike remote desktop but from Windows to LinuxWhat do I need to know?Linux server name: mintaka.lynchburg.eduyour username & password on mintaka5Linux Desktop6

Linux DesktopI thought Linux was text-basedwell use KDEa graphical user interface on top of Linux OScan use a mouse, windows, etcKDE is nice, butat its heart Linux is text-basedpeople used to log in remotely using special dumb terminalswell use the text-based interface too

7The ShellThe text-based interface to Linux8

The ShellThe shell is where users type commandssee results of those commands

9The ShellExample commandsdate: prints the date and timewho: prints who else is logged intop: shows resource usagelike Windows Task Managerman : shows a manual for command cmde.g., man dategrep [file]: search for a word or phrase in input or a file

10The ShellExample commandsps: prints commands you are currently runningkill : terminates the process with id pide.g.,

11meehean_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 psmeehean_j@mintaka:~$ kill 8688meehean_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 psThe ShellCan run commands in two modes:Foregroundshells assumes command is interactiveuser cannot run another command until foreground command finishesdefault mode

12The ShellCan run commands in two modes:Backgroundshell assumes command is not interactiveshell starts command, doesnt wait for it to finishcommand output will still be printed to screencommand must be followed by & to put into background

13The ShellInteracting with commands while runningCtl-C: kills foreground commandCtl-Z: suspends foreground commandfg: run background command in foregroundbg: run suspended command in background

14The ShellChaining commands togethercmd1 ; cmd2 ; cmd3run cmd1, then cmd2, then cmd3cmd1 | cmd2 | cmd3run cmd1run cmd2 using output of cmd1 as inputrun cmd3 using output of cmd2 as inpute.g., who | grep meehean_j

15The ShellFile input/outputcmd > out.txtrun cmd and store its output in out.txtdoes not print output to screene.g., who > users.txtcmd < in.txtrun cmd and use in.txt as its inputgrep meehean_j < users.txt

16The ShellThe wildcard: *it means match 0 or more characterse.g., who | grep m*prints all logged in users whose name starts with me.g, who | grep *m*prints all logged in users whose name has an m in it

17The ShellLike everything in Linux the shell is really just a programMany different optionsbash (the default)tcshzshIn KDE, need a visual display for the shella terminal emulatorcalled Konsole

18Questions?19How do I?Log inDo basic stuffUse the file systemAccess my files from WindowsEdit filesDo C++ developmentHand in my programs

20The File SystemRoot directorytop of the file systemlocated at /Each user gets a directory (folder)called the home directorylocated at: /home/Current working directory (cwd)where your shell will look for filescan change your current working directory21The File SystemDirectory name shortcuts/ : root~ : your home directory./ : your current working directory../ : the directory one up from the cwd../../ : the directory above ../Hidden filesstart with a .22The File Systemcommandspwd: print working directoryls: list the contents of the cwdlsls *.txt : list all files that end in .txtls a : list hidden files tools : list the contents of ls /tmp : list all files in /tmpcd : change cwd to cd ../ : move up one directorycd /tmp : move to the temporary directory23The File Systemcommandstouch : make a file called touch test.txt : make a file called test.txt in cwdtouch /tmp/a.wav : make a wav file in /tmprm : remove (delete) rm test.txt : remove file test.txt in cwdrm /tmp/a.wav : remove the file a.wav from /tmprm *.cpp : remove all files that end in .cpp

24The File Systemcommandsmkdir : make a directorycalled mkdir cs242 : make directory called CS242 in the cwdmkdir ~/cs242 : make cs242 directory in home dirrmdir : remove directory must be emptyrmdir cs242 : remove directory cs242 from cwdrmdir ~/cs242 : remove directory cs242 from homerm r : remove directory doesnt need to be empty

25The File Systemcommandscp : make a copy of called cp a.cpp a.cpp.bkup : create a copy of a.cpp called a.cpp.bkupmv : rename/move to mv a.cpp b.cpp : change a.cpp to b.cppmv a.cpp.bkup a.cpp : overwrite a.cpp with a.cpp.bkup

26The File Systemcommandscat : print file contents to screencat a.cpp : print a.cpp to screenless : open file using file reader lessless a.cpp : read a.cpp using lessuse arrows to move arounduse q to quit

27SambaNetwork file service for Linuxmaps your home directory in WindowsPreparationhave system admin add you as samba userlog in to mintakaset your samba password

28SambaMapping mintaka home directory in Windowsright click on Computerselect map network drivefolder: \\mintaka\select log in as different useruser: \password:

29Questions?30How do I?Log inDo basic stuffUse the file systemAccess my files from WindowsEdit filesDo C++ developmentHand in my programs

3132

EmacsSimple extensible editorcan edit several different languagescan run the debuggercan read your emailcan do everything really33EmacsTerminologybuffer: an open filekill: cutyank: pastepoint: cursormark: a user-specified locatione.g., kill from cursor to markregion: text between point and markwindow: emacs can be split into different buffers open at the same time

34EmacsStarting it up> emacs&Emacs documentation abbreviationsEsc = MCtrl = C (called command)Commands in emacsC-x C-f: open a fileC-x C-s: save the current buffer to its fileC-x C-c: close and exit

35EmacsSearch and replaceC-s: search forwardC-s fool : move point to next fool after pointC-r: seach backwardC-s fool : move point to previous fool before pointM-% : find and replaceinteractivedirections provided on screen

36EmacsKill and yankcopy and pasteC-k : kill to end of linecut from point to end of lineC-y : yank back last thing killedpaste at pointC-w : kill regionmultiple sequential kills are yanked back with one yank

37EmacsWindowsC-x 2: split into two windows, above and belowC-x 3: split window, side-by-sideC-x 0: delete this window (unsplit)C-x 1: delete all other windows beside this oneC-x o: move to another windowBuffersC-x b: select another buffer (open file)C-x C-b: select another buffer (from list)

38Vi39

ViEditor runs in terminalcannot use the mouseTwo modescommand modefor entering commandstext entry modefor inserting text into fileStarting up> vi file_to_edit

40ViWorking with files :e file : open file:w : save file:q! : quit without saving changes:x : save changes and quitInserting texta : switch to text entry mode after cursori : switch to text entry mode before cursorEsc: switch back to command mode

41

ViSearch /word: seach for wordn: search for next appearance of wordN: search for previous appearance of word

42

ViReplace :rs/foo/bar/a: replace foo with barr is range, can benothing: works only on current linenumber: works only on line number% : whole filea is argument, can be:g: replace all occurrences in line, not just firsti,I: ignore case, dont ignore casec: confirm each replace:%s/teem/team/g

43ViCut/Copy/Past/Undo x: cut current characterdd: cut lineXdd: cut X lines5ddD: cut to end of lineyy: copy linep: pasteu: undo

44Questions?45How do I?Log inDo basic stuffUse the file systemAccess my files from WindowsEdit filesDo C++ developmentHand in my programs

46Compiling by HandC++ compilation demystifiedcompile source files into binary object filesi.e., .cpp into .olink together multiple object files into a programi.e., combine multiple .o files into an executable

47Compiling by Handg++ is the Linux compiler for C++-c compilee.g., g++ -c file1.cpp file2.cpp file3.cpp-o linke.g., g++ file1.o file2.o file3 o executable

Useful options for g++-g: include debugging information-Wall: print out any warnings

48Compiling with Helpmake is a program that helps build other programsif you have a lot of filesit only builds the ones that changedor the ones that depend on the ones that changedlcmap.cpp depends on declarations in lcmap.hchanging lcmap.h requires recompiling lcmap.cpp

49Compiling with HelpHow does it determine the dependencies?you tell it using a makefilemakefileshould be named makefilecontains instructions on how to build your programvariables: Variable = valuedependencies: file.cpp: depedency.hcommands: command

50Compiling with Help51# commentCC = g++CFLAGS = -g Wall

# special default dependency all: hello_world

# tab is requiredhello_world: hello.o world.o$(CC) $(CFLAGS) o hello_world hello.o world.o

# to reference a variable you need $()hello.o: hello.h world.h hello.cpp$(CC) $(CFLAGS) c hello.cpp

world.o: world.h world.o$(CC) $(CFLAGS) c world.cppCompiling with Help52# special tag to clean upclean: rm f hello_world *.o Compiling with HelpHow do I use make?> makeruns make for the default target> make runs make for the make cleanmake hello_world

53Compiling with HelpHow do I figure out the dependencies?look at the includes for .h & .cpp filesWhat if a file1.h is dependent on file2.h?file1.h: file2.hno need for a command

54Compiling with HelpHow would I make a terrible makefile?

55CC = g++CFLAGS = -g WallHEADERS = hello.h world.hCFILES = hello.c world.cOBJS = hello.o world.o

all: hello_world

hello_world: $(OBJS)$(CC) $(CFLAGS) o hello_world $(OBJS)

$(OBJS): $(HEADERS) $(CFILES)$(CC) $(CFLAGS) c $(CFILES)Avoiding double inclusionIf you include the same .h file twiceg++ will think you are redefining structs, classes, and functionsAvoid by using include guards56#ifndef CLASSNAME#define CLASSNAME

// contents of your .h file

#endif /* CLASSNAME */Handing in assignmentsturnina Linux program to handin programming assignments -l: lists assignments-c : specifies course>turnin l c cs242f1357Handing in assignmentsturnin-p : hand in a projectmake a directory with your username.project> mkdir granger_s.pl> turnin p p1 c cs242f13 granger_s.p1overwrites all previous hand ins for p158Questions?59


Recommended