Lab 0: Using the Terminal

Lab 0: Using the Terminal

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 <arg>: change directory to <arg> – Sets the working directory to <arg> ● <arg> is relative to current directory – “..” maps the parent directory – “.” maps to the current directory – “~” maps to your home directory Navigating Around ● pushd <arg>: push working onto directory stack, and change directory to <arg> ● popd: pops directory off directory stack, changes working directory to popped value Navigating Around ● ls <arg>: 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 <filename> or nano <filename> – 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 Help ● man <command>: 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 ● mkdir, rmdir ● cp, rm, mv ● 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 .

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    15 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us