1 / 27

CS1010 DG (Week 2)

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).

dillian
Download Presentation

CS1010 DG (Week 2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1010 DG (Week 2) Tay Ray Chuan rctay@comp.nus.edu.sg 17 January 2012

  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)

  3. 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

  4. 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

  5. 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).

  6. 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

  7. 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.

  8. 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”.

  9. 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

  10. 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

  11. 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

  12. 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

  13. clear command • If the screen is too messy and you want to clear it, simple type command clear • Try the command by yourself. 13

  14. 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!!

  15. 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

  16. Development cycle vim gcc ./a.out

  17. vim – editor • Vim: VI Improved • vi vsemacs • emacs: editor macros

  18. Vim – at a glance • Command-mode • Insert mode i (insert before cursor), a (after) ESC

  19. Vim commands • :help • http://mislav.uniqpath.com/2011/12/vim-revisited/ • https://github.com/LevelbossMike/vim_shortcut_wallpaper/raw/master/vim-shortcuts_1280x800.png

  20. First C program

  21. gcc – compiler • cc • Unix implementation-specific Ccompiler • gcc • GNU Compiler Collection

  22. Compiling • gcc -Wall -lm example1.c • -Wall: Warnings=all (not really) • -lm: link to math library

  23. Recap: keyboard commands memorize practice

  24. Lab 0

  25. Spec Description: compute volume of box Given length=12, width=3, height=10 Then outputs “Volume = 360”

  26. 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;

  27. Submission • Download C file from sunfire, then upload to CodeCrunch • Deadline: 28 Jan (Sat), 6pm

More Related