Lab 0: Using the Terminal
CS220, Summer 2013 Tyler Stachecki
Shell
● Text-based, command interpreter. – sh, bash, csh, tcsh, ksh, …
● bash, csh most widely used
– Differences? Syntax.
● Same set of system commands available regardless of which shell you choose.
– Default is csh on our systems.
Shell
● Filesystem Organization – Broken into directories and files. – Outermost directory is always / (root) – External drives, other devices are 'mounted' as directories somewhere within the filesystem.
● mounts can exist within mounts
– Your home directory is always represented by ~
● On most systems, this maps to /home/username
Navigating Around
● pwd: print working directory – Prints the directory that you're “in”.
● cd
●
Navigating Around
● pushd
● popd: pops directory off directory stack, changes working directory to popped value
Navigating Around
● ls
● What happens when you pass no arguments?
● Some commands also have switches or options that you can pass that control the tool. – What does ls l do?
Creating Files
● Linux has a wide variety of text editors. – Try pico
● Syntax highlighting ● Regular expressions ● Shell interface within editor ● ...
Getting Help
● man
● Most tools also provide a --help or -h switch that outputs their usage.
Manipulating Files, Directories
● Use man to figure out what they do (if you can't tell by their names), and how to use them.
Some Development Tools
● gcc: The GNU C compiler
● g++: The GNU C++ compiler – gcc/g++ E will invoke the preprocessor (cc1) – Can also call cc, cxx, and cc1 directly.
● as: The assembler – gcc/g++ S will also invoke the assembler.
● ld: The linker – If you don't specify gcc/g++ c, then the tools will compile, assemble, and link all the C files you pass as arguments for you.
“Redirection”
● By convention, most programs read from stdin, or standard input. By default, the terminal maps this to your keyboard!
● Your terminal outputs the contents of stdout and stderr. Most programs, also by convention, write their output to these files.
● You can redirect the input and output to your program so that other files are used in place of stdin, stdout, and stderr.
“Redirection”
● To redirect stdin, use the < symbol in combination with a filename. – ./my_program_that_reads_input < input_data ● To redirect stdout, use the > symbol in combination with a filename. – ls l > directory_contents.txt ● To redirect stderr, use 2> in combination with a filename. – ls l 2> directory_contents.txt
Lab Assignment
● In your own words, describe the function of the following tools in two or more sentences. Be descriptive, and do not verbatim copy the man pages or from these slides. – cd, pushd, popd, cat, less, ls, chmod, chown, mkdir, rmdir, rm, cp, mv, tar, gcc, g++, as, and ld. – Name the file tools.txt
Lab Assignment
● Write a C program that outputs your name. Name the file name.c.
● Generate name.i (preprocessor output), name.S (compiler output), name.o (assembler output), and name (executable). Include all of them in your submission.
Lab Assignment
● Put all of the files in a directory: – yourBUid_cs220_lab0
● Create a tape archive (tarball), compress it, and submit it via Blackboard. – tar czvf yourBUid_cs220_lab0.tgz \ yourBUid_cs220_lab0