270 likes | 411 Views
CS1010 DG (Week 2). Outline for today. http://www.comp.nus.edu.sg/~cs1010/lab/gettingStarted.html sunfire (#2) Common Unix commands (#3) vim gcc Lab 0 ( http://www.comp.nus.edu.sg/~cs1010/lab/lab0.html ). Start Off (#2).
E N D
CS1010 DG (Week 2) Tay Ray Chuan rctay@comp.nus.edu.sg 17 January 2012
Outline for today • http://www.comp.nus.edu.sg/~cs1010/lab/gettingStarted.html • sunfire (#2) • Common Unix commands (#3) • vim • gcc • Lab 0 (http://www.comp.nus.edu.sg/~cs1010/lab/lab0.html)
Start Off (#2) • First of all, you need a SoC account to begin your programming journey (login to Sunfire). Apply for your SoC account at https://mysoc.nus.edu.sg/~newacct and follow instructions step by step. • You should have been granted access to CodeCrunch. Verify it by logging to the following website with your NUSNET id / password: https://codes.comp.nus.edu.sg
Sunfire Server • Sunfire is a UNIX server located in the SoC Machine Room. It is the sole platform that we will carry out C programming in CS1010. • To connect to Sunfire, you need to install a software called “SSH Secure Shell” (for Windows users), which is available in IVLE workbin. • All computers in SoCprogramming labs have already pre-installed “SSH Secure Shell”. 4
Connect to Sunfire • Launch a “SSH Secure Shell Client” (typically available on desktop after installation), click “Quick Connect” • Type Sunfire name and your SoC UNIX account (details on next page).
Connect to Sunfire (2) If you connect to Sunfire on campus, simply enter host name as: sunfire; for off campus (e.g., at home) connection, enter host name as: sunfire.comp.nus.edu.sg Enter user name as: your SoC UNIX account You will be prompted for password after you press <Enter> key; enter your UNIX account password and you are then connected to Sunfire. 6
Basic Unix commands (#3) • In a UNIX shell (like sunfire), you need a lot of typing but much less mouse clicking, compared with Windows operating system which you might be more familiar with. • There are a few useful commands that you need to remember which will facilitate your navigation in the UNIX world. • Practice is the best way to recognize UNIX commands. Gradually you will be more and more familiar with UNIX commands – so don’t worry too much at the beginning.
ls command • ls command (means list directory contents) will enable you to see all the files and sub-directories in current directory. • There are a few more complex usage of ls, but first of all, be familiar with the simplest one – just “ls”.
cd command (1) • cd command allows you to enter a designated directory. • e.g., cd public_html • After that, your working directory will be changed to your desired one (see picture below). Current folder changed 9
cd command (2) Current folder changed • You can also navigate to a subfolder of subfolder of subfolder… by giving full path. The folder structure of UNIX is similar to the Windows file system shown in a Windows explorer. • e.g., cd public_html/cs1101c/labs (destination folder must exist) 10
mkdir and rmdir commands Nothing happens since the folder is empty now Show a new sub-folder just created Nothing is shown as the sub-folder is just deleted • mkdir (means make directory) will create a sub-folder • rmdir (means remove directory) will delete an empty sub-folder 11
cp, mv and rm commands Test.c has been renamed as test.c (case-sensitive) • cp command copies a file to another folder. • mv command move a file to another folder. • mv command is also used to rename a file. • rm command deletes a file. 12
clear command • If the screen is too messy and you want to clear it, simple type command clear • Try the command by yourself. 13
Keyboard shortcuts for commands • Tab – autocomplete • Ctrl-R – search history • Ctrl-A – move cursor to start • Ctrl-E – move cursor to end • Alt-B – move back one word • Alt-F – move forward one word • Ctrl-W – delete word before cursor • Alt-D – delete word after cursor • Ctrl-L – clear screen • … super useful!!
Keyboard shortcuts for OS • Ctrl-C – kill • Ctrl-Z – sleep (not undo!) • fg (foreground) to bring it back • Ctrl-D – logout (EOF) • http://en.wikipedia.org/wiki/Bash_(Unix_shell)#Keyboard_shortcuts
Development cycle vim gcc ./a.out
vim – editor • Vim: VI Improved • vi vsemacs • emacs: editor macros
Vim – at a glance • Command-mode • Insert mode i (insert before cursor), a (after) ESC
Vim commands • :help • http://mislav.uniqpath.com/2011/12/vim-revisited/ • https://github.com/LevelbossMike/vim_shortcut_wallpaper/raw/master/vim-shortcuts_1280x800.png
gcc – compiler • cc • Unix implementation-specific Ccompiler • gcc • GNU Compiler Collection
Compiling • gcc -Wall -lm example1.c • -Wall: Warnings=all (not really) • -lm: link to math library
Recap: keyboard commands memorize practice
Spec Description: compute volume of box Given length=12, width=3, height=10 Then outputs “Volume = 360”
Calculating volume (assume v,l,w,h are all int) v = l * w * h; Q: Do we have worry about overflow? v = (long) l * w * h;
Submission • Download C file from sunfire, then upload to CodeCrunch • Deadline: 28 Jan (Sat), 6pm