<<

Lab 0: Using the Terminal

CS220, Summer 2013 Tyler Stachecki

Shell

● Text-based, interpreter. – sh, bash, csh, tcsh, ksh, …

● bash, csh widely used

– Differences? Syntax.

● Same set of system commands available regardless of shell you choose.

– Default is csh on our systems.

Shell

● Filesystem Organization – Broken into directories and files. – Outermost 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

: print working directory – Prints the directory that you're “in”.

: change directory to – Sets the working directory to

is relative to current directory – “..” maps the parent directory – “.” maps to the current directory – “~” maps to your home directory

Navigating Around

● pushd : push working onto directory stack, and change directory to

● popd: pops directory off directory stack, changes working directory to popped value

Navigating Around

: List directory contents – How would you list current directory contents?

● 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 or nano – Once you get into the habit of using these tools, you might want to look into vim or emacs

● Syntax highlighting ● Regular expressions ● Shell interface within editor ● ...

Getting

● man : Opens the manual page for a given command. – Try man 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 – If you don't specify gcc/g++ ­c, then the tools will compile, assemble, and 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, 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 sentences. Be descriptive, and do not verbatim copy the man pages or from these slides. – cd, pushd, popd, , , ls, , chown, mkdir, rmdir, rm, cp, mv, tar, gcc, g++, as, and ld. – Name the 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