Handin and Linux and CS Systems - Getting Started: Difference between pages

From Computer Science at Indiana State University
(Difference between pages)
Jump to navigation Jump to search
wiki_previous>Jkinne
 
 
Line 1: Line 1:
== The handin program ==
This page is meant to help a new student in a CS course at ISU to get familiar with using Linux (in particular using the text-based terminal to interact with the system).
Handin is a program for checking out and handing in assignmentsThere is an online manual entry for handin and all associated programs, so you can type:
 
<pre>
=Getting Started=
man handin
# '''Read''' - [https://ubuntu.com/tutorials/command-line-for-beginners#1-overview Ubuntu Linux Command Line Tutorial] or [http://www.ee.surrey.ac.uk/Teaching/Unix/ Linux Tutorial] - this gives you some background and introduces you to some of the terms that we use.  After reading through the tutorial you have a better chance of being able to follow along the rest of the steps in this Getting Started.
</pre>
# '''System Setup''' - [[Linux - System Setup]] - to get your computer setup (programs installed, etc.).
# '''Using the Terminal'''
## [[Linux Terminal - Files and Directories and Getting Around]]
## [[Linux Terminal - System Information]]
## [[Linux Terminal - Text Editors]]
## [[Using Linux - Large Text Files]]
## [[Linux Terminal - More Commands to Know]]
 
=Common Mistakes=
* When logging in remotely to the CS server, when you are typing your password you might not see anything printed on your screen while you type.  That is a security feature so that someone watching your screen would not know how many characters are in your password.  Just finish typing your password and type enter when finished.
* Note that all commands and file names in Linux are '''case sensitive'''.  hello.txt is different than Hello.txtThe copy command is cp, Cp would not work, and neither would cP or CP.
* The characters _ and - are different, and having a space in a file name is different than not having one ("hello world.txt" is different than "helloworld.txt").
* For Linux directories and filenames, the "/" character is used to separate directories.  On Windows, the "\" character is used instead.  If you typed <pre>cd /home/cs151</pre> then this changes the directory to the cs151 user's home directory.  If you instead typed <pre>cd \home\cs151</pre> you would get an error.
* The "top" or "highest level" of the Linux file system is the directory / and this is comparable to the "C:\" that was traditionally the top of the file system in Windows.  In Windows there can be multiple drives (so D:\, E:\, etc.), but in Linux '''everything''' is underneath / (including additional drives, they will show up at a certain location under /).
* On Linux, ~ is a shortcut for your home directory.  User jkinne@isuad.indstate.edu's home directory is in /home/jkinne@isuad.indstate.edu, so if this user is logged in and types <pre>cd ~</pre> then this means to change directories to /home/jkinne@isuad.indstate.edu/.  If user jeff types <pre>cd ~</pre> then this means to change directories to jeff's home directory (which happens to be /home/jeff/).
* Not all sequences of commands are ''idempotent'' - this is a technical term that means that the sequence of commands gives the same results if executed more than once. For example, executing <code>echo "hello world!" >> hello.txt</code> once creates a file hello.txt that has one line in it, but executing again makes the file have two lines. When you see a sequence of commands to run to complete some task (e.g., from an online tutorial) be careful to execute one command after the other, all the way through, stopping after each to make sure you know what that step was supposed to do.
* Sometimes the precise syntax of commands might depend on which shell program you are using. bash is the default shell program on the CS server, but  zsh is commonly used instead.  You can see which shell you are running by executing the <code>ps</code> command and seeing which one is in the printed output from that command.  For example, the command for displaying your resource limits is <code>ulimit -a</code> in bash and zsh, but is <code>limit</code> in tcsh. When looking up how to do things online, it is good to include your shell in the search terms (e.g., search for - bash get resource limits - rather than just - get resource limits).
 
=More Reading=
Read through another tutorial about Linux.  Some options include the follow.
* [http://www.linuxcommand.org/ Linux Console Tutorial]
* [http://www.reallylinux.com/ Information for Beginning Linux Users]
* [http://cs.indstate.edu/~sbaker/faq/QuickRefCard.pdf Unix/Linux Quick Reference Card]
 
=Self Test=
Note: a practice quiz over linux commands and the terminal is here - https://indstate.instructure.com/courses/12565/quizzes/244584
 
Here we give small tasks for you to complete.  These are numbered so that we can refer to them.  For each you would need to be logged into one of the CS systems (remotely logged into the CS server or using one of the CS lab computers).
 
''Linux.0'' Log in to the CS server, and run the chfn command to put your name into the system.  You can leave all the other fields blank (just type enter).  Also, use the chsh command to change your default shell from /bin/tcsh (or whatever it is) to /bin/bash
 
''Linux.1'' Log in to the CS server, create a directory named aboutMe in your home directory, and create a text file name.txt.  In the name.txt file, give your full name.
 
''Linux.2'' In your aboutMe directory, create a file courses.txt and list which CS courses you are currently taking or plan to take in the upcoming term.
 
''Linux.3'' Log in to the CS server, create a directory named notes in your home directory, and create a text file named linux.txt and put in some links to linux tutorials or information that you have found helpful.


at your prompt if you need to refer to the documentation.
''Linux.4'' Log in to the CS server, create a directory named linux-bootcamp in your home directory.


=== Displaying Outstanding Assignments ===
''Linux.5'' In your linux-bootcamp directory, create a text file shake.txt.  In shake.txt, put how many lines are in the shakespeare.txt file mentioned in the information above.
By itself, executing handin with no additional command line parameters will display all the class assignments and their due dates. It will also display the last time a specific assignment was submitted, so that you can check your submissions.


<pre>
''Linux.6'' In your shake.txt file, add information about how many times "the" appears in shakespeare.txt.  Use the command grep,
handin
add to what you had how many lines "the" appears in shakespeare.txt.  Hint - use the -c option for grep, also use the -i option so your count will also include "The", "THE", etc.  In your shake.txt, you should have the number of lines that contain "the" (including "The", etc.), and also the percentage of the lines that contain the.
  Assignments:
  h1, due 2020-01-17 23:59:59
    - Last submitted on Sun Jan 12 13:16:16 2020
  h2, due 2020-01-24 23:59:59
</pre>


If your account is not a class account (does not start with something like cs151 or cs500), you can still check, checkout and handin assignments for a specific class using the <code>-c</code> (equivalently, <code>--class</code>) option followed by the class name in question:
''Linux.7'' In your linux-bootcamp directory, create a text file weather.txt.  Copy the Indianapolis weather csv file from /u1/junk/weather/ into your linux-bootcamp directory.  In your weather.txt file, put how many rows of data are in the csv file (use wc, head, and tail).  Assuming 365 days per year, put in your weather.txt file how many years of data are in the csv file.
<pre>
handin -c cs456
</pre>


would select the cs456 class and then display the assignments for the class.
''Linux.8'' In your weather.txt file, put the maximum PRCP, SNOW, SNWD, TMAX, TMIN, MEAN from the csv file.  Hint - use the sort command, and use the options -t, -k, -n, -o.


=== Checking Out an Assignment ===
=Assignment 0=
Assignments can be copied to your directory using the <code>-C</code> or <code>--checkout</code> option followed by the name of the assignment, i.e.
The following is a typical first assignment to get started in Linux on the CS server. Here we assume your login on the server is YOUR_LOGIN (this would typically be something like <code>cs15100</code> for a class account or something like <code>jkinne</code> for a permanent CS account).
<pre>
handin -C h4
</pre>
would copy the h4 assignment directory to your account where you can then begin working on your assignment.


=== Submitting Your Assignments ===
==Account Configuration==
When you have done some work on your assignment, you an submit your assignment using handin followed by the name of the assignment directory i.e.:
Update your password, change your "finger" information (put your true name and can leave the rest blank), and set your normal shell. You execute each of these commands, one after another.
<pre>
<pre>
cd ~
passwd
handin h4
chfn
</pre>
chsh -s /bin/bash YOUR_LOGIN
will submit the h4 assignment.  Note that this should be done in the parent directory where the assignment directory is.  If you are using your class account for the assignment (e.g., you are logged in with your cs151 account and working on an assignment for cs151), you can also submit from with your assignment working directory:
<pre>
cd ~/h4
submit
</pre>
</pre>
You can see which other shells you can choose from (other than bash) with <code>cat /etc/shells</code>.  Bash reads configuration information from a file <code>~/.bashrc</code>.  A file with good defaults for the CS server are at [https://cs.indstate.edu/~jkinne/training_files/.bashrc .bashrc]. More help on bash - [https://www.gnu.org/software/bash/manual/ bash manual].


You can submit your assignment as many times as you like until the due time has passedIf an assignment allows late submissions, they will be submitted into the late submissions directory. You should submit early and often, as submitting your assignments can be used as a form of backup.
If you want to see what commands you have run in the current login session you can run the command <code>history</code>Bash also keeps history from previous sessions in the file <code>~/.bash_history</code>.


=== Grading Notes ===
You should create the following directories and use (a) your <code>bin</code> directory to put programs or scripts that you have downloaded or created that you want to be able to use, (b) your <code>programs</code> directory to put installation files for programs that you might need, (c) your <code>private</code> directory to keep files you want to make sure to keep private from other users, and (d) your <code>public_html</code> directory to store files that you want to be accessible on the web (at https://cs.indstate.edu/~YOUR_LOGIN).
Once your assignment has been graded, you may be able to check the grading notes for the assignment using the -g option which will print the grading notes for the assignment, assuming they have been submitted by your professor.
<pre>
<pre>
handin -g h4
mkdir ~/bin/
echo "export PATH=$PATH:~/bin/" >> .bashrc  # add the ~/bin/ directory to where shell looks for programs
mkdir ~/programs/
mkdir ~/private/
chmod go-rwx ~/private/    # makes that directory not accessible to other users
mkdir ~/public_html/
chmod go+rx ~/public_html/ # so the web server can access this directory
chmod go+x ~              # so the web server can access your public_html
</pre>
</pre>
Note that the web server is Apache, so if you want to configure how it processes files in your account, you should look for help on the Apache web server. It is also possible to run a web server using node.js; you can look up tutorials for how to do that.


=== Checking Your Work With --hwcheck ===
==Copying/Creating/Editing Files==
Some assignments may allow auto-checking, which can be accessed using the --hwcheck switch to handin.
Create a file in your <code>public_html</code> directory, and practice copying a file from somewhere else on the system.
<pre>
<pre>
handin --hwcheck h4
cd ~/public_html
nano hello.txt  # or use your preferred editor - vim, emacs, jove, ...
# type something in your hello.txt file, save it, and
#  check that you can view it at https://cs.indstate.edu/~YOUR_LOGIN/hello.txt
cp /usr/dict/words . # copies that file into current directory, which should still be your public_html
# now check https://cs.indstate.edu/~YOUR_LOGIN/words
</pre>
</pre>
would check your work for the h4 assignment. You need to be in the assignments parent directory for the option to work, for that reason there is a helper script called 'check' that streamlines auto-checking your work while you are in the assignment directory.
Create a sub-directory within your <code>public_html</code> directory, put some file there, edit the Apache configuration file (<code>.htaccess</code>) to allow directory listing of this directory (turned off by default for security reasons).
<pre>
<pre>
cd ~/h4
cd ~/public_html
check
mkdir files_public
cd files_public
echo "Options +Indexes" >> .htaccess
ls -a        # verify that the .htaccess file exists now
cat .htaccess # see what is in the file now
cp /u1/junk/kinne/text-samples/shakespeare.txt .
cp /u1/junk/kinne/text-samples/austen.txt .
# Now browse to https://cs.indstate.edu/~YOUR_LOGIN/files_public
</pre>
</pre>
runs the hwcheck on h4 w/o needing to be in the parent directory.  It will also attempt to run make if applicable to build any programs that require building.


In either case, the program checks the output of your program against the output of the instructor's solution on various inputs. If your program is incorrect on any test inputs, this information is printed.
==Long Running Jobs==
If you have a process that needs to run for more than a few minutes, you should run it like this:
<pre>time nice -n 19 whatever_command</pre>
Starting the command with <code>time</code> will give you a printout afterwards of how much time the job took (<code>man time</code> for more details). Having <code>nice -n 19</code> makes your long running job run at a lower priority. Your job will finish just as fast, but it will interfere less with more important processes (other users on the system).
 
If the job is going to take an hour or more, you probably want to run it like this:
<pre>time nice -n 19 whatever_command > output.txt 2>stderr.txt &</pre>
The <code> > output.txt</code> will have output go to the output.txt file, and <code> 2>stderr.txt</code> (no spaces is important) redirects error output to stderr.txt. The <code>&</code> will detach the process from your terminal so that it can continue running even if your terminal disconnects. You can login again and check on it by running <code>ps a</code> to see all your running processes (not just the ones started on the current login).
 
Alternatively to redirecting the output and detaching, you could use the <code>screen</code> command to run the command in a terminal that you can detach. You can lookup help on the screen command for how to do that (for example, [https://www.geeksforgeeks.org/screen-command-in-linux-with-examples/ here]).

Revision as of 11:30, 29 September 2025

This page is meant to help a new student in a CS course at ISU to get familiar with using Linux (in particular using the text-based terminal to interact with the system).

Getting Started

  1. Read - Ubuntu Linux Command Line Tutorial or Linux Tutorial - this gives you some background and introduces you to some of the terms that we use. After reading through the tutorial you have a better chance of being able to follow along the rest of the steps in this Getting Started.
  2. System Setup - Linux - System Setup - to get your computer setup (programs installed, etc.).
  3. Using the Terminal
    1. Linux Terminal - Files and Directories and Getting Around
    2. Linux Terminal - System Information
    3. Linux Terminal - Text Editors
    4. Using Linux - Large Text Files
    5. Linux Terminal - More Commands to Know

Common Mistakes

  • When logging in remotely to the CS server, when you are typing your password you might not see anything printed on your screen while you type. That is a security feature so that someone watching your screen would not know how many characters are in your password. Just finish typing your password and type enter when finished.
  • Note that all commands and file names in Linux are case sensitive. hello.txt is different than Hello.txt. The copy command is cp, Cp would not work, and neither would cP or CP.
  • The characters _ and - are different, and having a space in a file name is different than not having one ("hello world.txt" is different than "helloworld.txt").
  • For Linux directories and filenames, the "/" character is used to separate directories. On Windows, the "\" character is used instead. If you typed
    cd /home/cs151
    then this changes the directory to the cs151 user's home directory. If you instead typed
    cd \home\cs151
    you would get an error.
  • The "top" or "highest level" of the Linux file system is the directory / and this is comparable to the "C:\" that was traditionally the top of the file system in Windows. In Windows there can be multiple drives (so D:\, E:\, etc.), but in Linux everything is underneath / (including additional drives, they will show up at a certain location under /).
  • On Linux, ~ is a shortcut for your home directory. User jkinne@isuad.indstate.edu's home directory is in /home/jkinne@isuad.indstate.edu, so if this user is logged in and types
    cd ~
    then this means to change directories to /home/jkinne@isuad.indstate.edu/. If user jeff types
    cd ~
    then this means to change directories to jeff's home directory (which happens to be /home/jeff/).
  • Not all sequences of commands are idempotent - this is a technical term that means that the sequence of commands gives the same results if executed more than once. For example, executing echo "hello world!" >> hello.txt once creates a file hello.txt that has one line in it, but executing again makes the file have two lines. When you see a sequence of commands to run to complete some task (e.g., from an online tutorial) be careful to execute one command after the other, all the way through, stopping after each to make sure you know what that step was supposed to do.
  • Sometimes the precise syntax of commands might depend on which shell program you are using. bash is the default shell program on the CS server, but zsh is commonly used instead. You can see which shell you are running by executing the ps command and seeing which one is in the printed output from that command. For example, the command for displaying your resource limits is ulimit -a in bash and zsh, but is limit in tcsh. When looking up how to do things online, it is good to include your shell in the search terms (e.g., search for - bash get resource limits - rather than just - get resource limits).

More Reading

Read through another tutorial about Linux. Some options include the follow.

Self Test

Note: a practice quiz over linux commands and the terminal is here - https://indstate.instructure.com/courses/12565/quizzes/244584

Here we give small tasks for you to complete. These are numbered so that we can refer to them. For each you would need to be logged into one of the CS systems (remotely logged into the CS server or using one of the CS lab computers).

Linux.0 Log in to the CS server, and run the chfn command to put your name into the system. You can leave all the other fields blank (just type enter). Also, use the chsh command to change your default shell from /bin/tcsh (or whatever it is) to /bin/bash

Linux.1 Log in to the CS server, create a directory named aboutMe in your home directory, and create a text file name.txt. In the name.txt file, give your full name.

Linux.2 In your aboutMe directory, create a file courses.txt and list which CS courses you are currently taking or plan to take in the upcoming term.

Linux.3 Log in to the CS server, create a directory named notes in your home directory, and create a text file named linux.txt and put in some links to linux tutorials or information that you have found helpful.

Linux.4 Log in to the CS server, create a directory named linux-bootcamp in your home directory.

Linux.5 In your linux-bootcamp directory, create a text file shake.txt. In shake.txt, put how many lines are in the shakespeare.txt file mentioned in the information above.

Linux.6 In your shake.txt file, add information about how many times "the" appears in shakespeare.txt. Use the command grep, add to what you had how many lines "the" appears in shakespeare.txt. Hint - use the -c option for grep, also use the -i option so your count will also include "The", "THE", etc. In your shake.txt, you should have the number of lines that contain "the" (including "The", etc.), and also the percentage of the lines that contain the.

Linux.7 In your linux-bootcamp directory, create a text file weather.txt. Copy the Indianapolis weather csv file from /u1/junk/weather/ into your linux-bootcamp directory. In your weather.txt file, put how many rows of data are in the csv file (use wc, head, and tail). Assuming 365 days per year, put in your weather.txt file how many years of data are in the csv file.

Linux.8 In your weather.txt file, put the maximum PRCP, SNOW, SNWD, TMAX, TMIN, MEAN from the csv file. Hint - use the sort command, and use the options -t, -k, -n, -o.

Assignment 0

The following is a typical first assignment to get started in Linux on the CS server. Here we assume your login on the server is YOUR_LOGIN (this would typically be something like cs15100 for a class account or something like jkinne for a permanent CS account).

Account Configuration

Update your password, change your "finger" information (put your true name and can leave the rest blank), and set your normal shell. You execute each of these commands, one after another.

passwd
chfn
chsh -s /bin/bash YOUR_LOGIN

You can see which other shells you can choose from (other than bash) with cat /etc/shells. Bash reads configuration information from a file ~/.bashrc. A file with good defaults for the CS server are at .bashrc. More help on bash - bash manual.

If you want to see what commands you have run in the current login session you can run the command history. Bash also keeps history from previous sessions in the file ~/.bash_history.

You should create the following directories and use (a) your bin directory to put programs or scripts that you have downloaded or created that you want to be able to use, (b) your programs directory to put installation files for programs that you might need, (c) your private directory to keep files you want to make sure to keep private from other users, and (d) your public_html directory to store files that you want to be accessible on the web (at https://cs.indstate.edu/~YOUR_LOGIN).

mkdir ~/bin/
echo "export PATH=$PATH:~/bin/" >> .bashrc  # add the ~/bin/ directory to where shell looks for programs
mkdir ~/programs/
mkdir ~/private/
chmod go-rwx ~/private/    # makes that directory not accessible to other users
mkdir ~/public_html/
chmod go+rx ~/public_html/ # so the web server can access this directory
chmod go+x ~               # so the web server can access your public_html

Note that the web server is Apache, so if you want to configure how it processes files in your account, you should look for help on the Apache web server. It is also possible to run a web server using node.js; you can look up tutorials for how to do that.

Copying/Creating/Editing Files

Create a file in your public_html directory, and practice copying a file from somewhere else on the system.

cd ~/public_html
nano hello.txt  # or use your preferred editor - vim, emacs, jove, ...
# type something in your hello.txt file, save it, and
#  check that you can view it at https://cs.indstate.edu/~YOUR_LOGIN/hello.txt
cp /usr/dict/words . # copies that file into current directory, which should still be your public_html
# now check https://cs.indstate.edu/~YOUR_LOGIN/words

Create a sub-directory within your public_html directory, put some file there, edit the Apache configuration file (.htaccess) to allow directory listing of this directory (turned off by default for security reasons).

cd ~/public_html
mkdir files_public
cd files_public
echo "Options +Indexes" >> .htaccess
ls -a         # verify that the .htaccess file exists now
cat .htaccess # see what is in the file now
cp /u1/junk/kinne/text-samples/shakespeare.txt .
cp /u1/junk/kinne/text-samples/austen.txt .
# Now browse to https://cs.indstate.edu/~YOUR_LOGIN/files_public

Long Running Jobs

If you have a process that needs to run for more than a few minutes, you should run it like this:

time nice -n 19 whatever_command

Starting the command with time will give you a printout afterwards of how much time the job took (man time for more details). Having nice -n 19 makes your long running job run at a lower priority. Your job will finish just as fast, but it will interfere less with more important processes (other users on the system).

If the job is going to take an hour or more, you probably want to run it like this:

time nice -n 19 whatever_command > output.txt 2>stderr.txt &

The > output.txt will have output go to the output.txt file, and 2>stderr.txt (no spaces is important) redirects error output to stderr.txt. The & will detach the process from your terminal so that it can continue running even if your terminal disconnects. You can login again and check on it by running ps a to see all your running processes (not just the ones started on the current login).

Alternatively to redirecting the output and detaching, you could use the screen command to run the command in a terminal that you can detach. You can lookup help on the screen command for how to do that (for example, here).