Skip to content

Computing Tools for CS studies exercises week 1: Department's Ubuntu environment

emlai edited this page Sep 9, 2016 · 8 revisions

Welcome! This document holds the first week's exercises. They're best to be done at paja (hands-on lab). It's also best to do them with department's computers, as with your own computer some tasks are different. However, if you have a new Ubuntu installation on your computer, it should be enough.

IMPORTANT

Everyone should submit their completed excercises to the LapioStats service. You should create an account on the site with your own student ID. This is important, since all your progress is tracked through the site.

The software is open source software, and you can view the code and make it better on Github. If you don't know what this means yet, it's no problem.

Help is available on the Internet. In particular, department's IT pages are useful.

The material here won't tell the whole story. Since we are studying computer science, online search engines are a really important part of finding information, not just on this course but on all the courses in our department. If you don't find or figure out the answer right away, don't panic, the instructors in paja will help you. Some of the exercises are really simple though, so it will be difficult for the instructor to give you a hint without spoiling the solution!

If you have some feedback or comment regarding the instructors it is very welcome to Chang Rajani at chra (at) cs.helsinki.fi.

Instead of numbering, tasks are named [like-this]. This way they can be unambiguously referred to and searched via web browser's search tool (ctrl + f).

[ubuntu]

Boot the machine into Ubuntu, if it is on Windows. Or turn on the machine if it is not on.

[username]

Activate your user account :)

http://www.cs.helsinki.fi/en/compfac/user-accounts for instructions.

While at it, also register to this course (if you haven't already). Thank you!

[email]

Configure your department e-mail into Thunderbird (email client).

Department's email autoconfigures into Thunderbird (also on your home computer) when you put your e-mail address as [email protected]. You can change the address later as first.last@[cs.]helsinki.fi.

See cs dept instructions. Test by sending yourself e-mail.

On later task [email-redirect], you redirect the helsinki.fi mail into cs.helsinki.fi mailbox.

[terminal]

Open a Terminal (Dash → type in "Terminal"). Execute command ls -l.

Dash is the master launcher with Ubuntu logo on the top-left corner. It appears also with the Windows key.

Search the Web for random lolcat and save the image to your home directory→Downloads folder (which is the default for web browsers). Repeat command ls -l. Can you see the lolcat?

It shouldn't be visible, although the Downloads folder timestamp has changed. Change the directory: cd Downloads. Repeat ls -l. Can you see it now?

Open the file browser into your home directory (top-left "Home Folder" -launcher). Find lolcat.

Terminal lists your home directory files with command ls, as does the graphical file browser. In computer science, useful tools are often on the command line, and that's what we prefer on this course!

[mkdir]

Create a työväline (or pick a name) directory into your home folder. There you can save the shell scripts etc. generated during this course.

Tutorial: https://help.ubuntu.com/community/UsingTheTerminal

And hey! Terminal is magic. Up/down arrow keys browse old commands. Tab (on the left of the letter q) completes commands and filenames. And because the ctrl + c and ctrl + v are special in terminal, copy-paste is ctrl + shift + c and ctrl + shift + v.

For all the commands, you get help with man command or help command.

Man is a browser for manual pages. It displays odd groff-formatted text files. Man has same navigation commands as less, most important of which are:

key function
Down/Up scroll down / up
PageDown/PageUp scroll down / up page at a time
< > go to the beginning / end
/ get text (asking what looking for)
n search for the next search results to previous search term
h help
q to exit man / less-browser

[ssh]

Open another terminal. Do a text-based remote access to the server shell: ssh shell.cs.helsinki.fi. Enter password when asked. If you are doing this from your own computer, the correct command is ssh <username>@shell.cs.helsinki.fi where <username> is your university username. Run ls -l. Should look the same as the ls commands in previous exercises.

On Windows you can use Putty.

In the future there will be more ssh tasks. The previous directory listing commands (ls -l) list the contents of your home directory. Your home directory is a network drive, and is physically located in the basement at file server fs. Previous ls commands were run from a local paja computer (for example, called dac-40). On this task, it was run remotely on machine shell.cs.helsinki.fi (which is an alias for melkinpaasi.cs.helsinki.fi).

[home directories]

You have two different home directories.

  • Helsinki University (AD) home directory (local/paja computers and department's servers) located at /home/<username here>
  • CSFS (CS) home directory located at /cs/home/<username here>

Make a symbolic link in your AD home directory which points to your CSFS home directory, with the following command:
ln -s ........ .......

Check out the ln command manual by typing man ln and find out how to create a symbolic link.

[rdesktop]

Do a remote connection to a remote server installation of Windows (winserver.cs.helsinki.fi).

rdesktop -D -g workarea -xp -d TKTL -u yourusernamehere winserver.cs.helsinki.fi

man rdesktop tells you what the parameters do. -D -g workarea scam gives the full screen mode with Ubuntu-beams are visible, as the official "f" in full-screen mode can not get off.

On Windows there's "Remote Desktop Connection". On OS X you can use Microsoft remote desktop, or nice free Cordin.

[ubuntu-launcher]

Add Terminal as Unity launcher (the left edge of screen). Instructions.

Also add the useful Remote Windows as a launcher.

Later Ubuntu releases made adding custom launchers a wonderful (and therefore irrational) difficult experience (left as Google translated). On cs, the gnome-desktop-item-edit command from the link works as such. NB. created launcher (.desktop file) goes to the desktop, where it still needs to be added as Unity launcher.

Nice scalable Windows icon for the launcher, click here: http://www.cs.helsinki.fi/u/skaipiai/windows.svg

[gedit]

Open gedit the text editor. Turn on settings: visible line numbers, "highlight current line" and "highlight matching bracket". Also turn on the useful side-panel file browser.

Report current feelings into the työväline directory you created on task [mkdir], as file Friday.

Other text editors: the excellent Sublime Text.

[nano]

Ideal as a text-based text editor for small modifications is nano. Try it by creating a file Hello.java which consists of the following hello world localization:

public class Hello {

 public static void main(String[] args) {

   System.out.println("Hello Kumpula!");

 }

}

Command nano Hello.java. Copy-paste, save and exit nano: ctrl + x, y, enter.

Compile and run the file that you created in java: javac Hello.java, java Hello.

Nano commands: ctrl + x to exit (you are asked to save, if you have made ​​changes to a file). ctrl + o to save, but not exit nano. More commands at the bottom of the nano.

Btw. Putty-ssh and nano allows you to program Java from home Windows. Open two Putty ssh windows. On first, command nano Moi.java, ctrl + o to save. The second javac Moi.java && java Moi. However, this is of course better with an IDE, such as NetBeans.

[nano-2]

Configure autoindent to nano. Needed commands: man nanorc, nano .nanorc.

[alias]

Make the following aliases (helper commands).See help alias or internet. Wikipedia has a good article about aliases.

  1. alias manh which executes the command man --html=chromium-browser (ie open the requested man page in Chromium browser). More comfortable to watch the man pages in your browser!

    Bonus: also might be interested in the following: man -t bash | ps2pdf - bash.pdf. This you can't make ​​an alias, because the variable / parameter "bash" occurs not only in the end of command. On the other hand one can do shell script (replace "bash" → "$1"), and on week 3 we'll do that!

  2. alias ls, which executes the command ls --color=auto, that is, overwrite the default ls command with the command which colors the files/directories based on their type (file extension).

  3. alias o, which executes the command ls -latr, ie list files in…

    • l: long format,
    • a: also "hidden" files starting with a point ".",
    • t: sorted by (modification) time stamp,
    • r: reverse order, ie the newest files at the bottom.

It is typical to use o-alias almost always instead plain ls, because one is often particularly interested in the latest files. The name is "o" for historical DOS reasons; you can, of course, give any name you wish for your aliases.

[alias-2]

Save all the aliases into file named .bash_aliases (note the dot at the beginning) in your home directory. The command "alias" list current aliases (so you can copy-paste). When saved, the aliases work in all future terminal sessions, including over ssh!

Test: open a new terminal, command o (also colors should appear), also try manh nano.

.bash_aliases is a regular text file. The dot in the beginning of the filename makes the file hidden in most normal contexts. Generally all the Linux configuration files are named this way and are hidden by default. Lots of these files are in your home directory. Neither file browsers or “ls” show them by default, but adding “-a” parameter for the “ls” command reveals them. Try “ls -la”. Also the graphical file browser can show “hidden” dot-files: View > Show hidden files.

OBS. On paja computers, you need to add file .bashrc (note the dot) to your AD home directory, and into there the following line which stock Ubuntu already has (note the dot at the beginning):

source ~/.bash_aliases

OBS2. And to make it work via ssh sessions too, on CS computers you need to copy .bash_aliases and .bashrc to your CS home directory and add following line (note dot) into your .profile file:

source "$HOME/.bashrc"

More info about the OBS notes (login and non-login shell).

[email-redirect]

The university & CS dept offers you the following email addresses:

  1. [email protected] (alias) → routed by default to [email protected]
  2. [email protected] (university)
  3. [email protected] (new students do not no longer cc-IDs)
  4. [email protected] (alias) → routed to [email protected]
  5. [email protected] (cs department)
  6. first.last addresses also have versions in which the initial letters are uppercase (First.Last)

There's webmails available at https://webmail.helsinki.fi (for university mail) and https://webmail.cs.helsinki.fi (for cs dept mail). Both mails can also be configured into Thunderbird.

The task: choose how you want to redirect your email, and do so following the instructions.

  1. helsinki.fi mail → [email protected] mailbox (recommended),
  2. cs.helsinki.fi mail → [email protected] mailbox,
  3. or maybe all of the University of email into gmail/elsewhere?

Test by sending e-mail to the address, which you redirected to another address.

[http]

Let's use the wget command and download the first week of MOOC to our computer (remember man wget!). First open the file with a text editor of your choosing (nano, gedit). What do you notice? Next open it up in the browser with the command firefox <filename> (the file is likely called index.html). Now it looks a bit better, but there's still something wrong.

This is because we only downloaded the HTML source code of the website. Web pages also consist of Javascript and CSS, both of which we didn't download. We'll take a more in-depth look at these two in the following week.

[ssh-irc]

IRC is a very useful tool in CS studies, and you can find help there for almost any course. It's extremely useful to set it up.

  1. Set up Screen and Irssi. It’s easiest to follow the instructions in fuksiwiki, so maybe ask a Finnish friend or one of the paja-tutors to help you out. There is also a more advanced tutorial. No need to really start using IRC though.
  2. On your home computer, create an alias irc (or anything you like) in your .bash_aliases. This should automatically connect to the department (melkki.cs.helsinki.fi) via ssh, and run the command screen -dr. The ssh command requires the parameter -t, so that it will run screen for "pseudo-tty" (see man ssh).

BONUS: On the server running your irc-screen (melkki.cs.helsinki.fi) add a line to cron to launch irc-screen automatically at reboot. The screen command requires the options -d and -m, so that it will run triggered by the cron daemon (cf. Screen tutorial).

Ps. remove the cron-line if you don’t use IRC.

[public_html]

Publish your home page on the Internet: http://cs.helsinki.fi/u/username (replace username with your own.)

  1. Make a new directory "public_html" in your CS home directory.
  2. Create a document "index.html" in the directory. “Hello World!” will do fine.
  3. Set the file permissions on your home directory (~), public_html and index.html so that you can see the contents of index.html when you browse to http://cs.helsinki.fi/u/username
  4. For settings the permissions: man chmod.
  5. This way: files should have "go+r", directories "go+x".
  6. Probably the permissions are about right from the get go, but home directory is missing “go+x”.

Wikipedia knows how to change the file permissions. Do this:

  • On your terminal change to directory public_html, where ls -la shows all the files and directories, which need fiddling.

  • . (dot) refers to current working directory (public_html) and .. (dotdot) to the parent directory (which is in this case ~).

Objective:

skaipiai@wel-68:~/public_html$ ls -la
drwx--x--x 115 skaipiai tkol     8192 2011-09-07 15:27 .
drwx--x--x  90 skaipiai tkol     4096 2011-09-07 15:27 ..
-rw-r--r--   1 skaipiai tkol        5 2011-09-07 15:19 index.html

On the Department computers, and more generally on Ubuntu, the default permissions for files are -rw-r--r--, i.e. you have read/write permission while group and others have only read permission. Default permissions can be altered using the command umask.

[git]

Git is a very useful tool that is used on many of the department's courses, as well as in working life. In addition there's a service named Github which is also very widely used. A quick summary of what git and Github are can be found here. We'll take a quick peek at what git is by cloning a repository. The link about clarifies this. In the context of git, cloning is when we copy the source code of an entire project to our own machine.

Git can be found on the department's computers and on all Ubuntu installations. Clone (the command is git clone, man git-clone helps!) a repository of your liking to your computer and have a look at it's insides. Some examples of Java-repositories are JUnit and Google Guava

[plan]

Create a .plan (there’s a dot!) file on your AD home directory using one of the Linux-servers. You can use your favorite text editor or redirect the output of the echo command on the terminal to create the file. Output is redirected using the > operator.

Type cat .plan to output the file contents. Use chmod a+r .plan to make the file readable to world and finger username to reveal your WORLD DOMINATION PLANS.

You can try to get wind of your neighbors plans using the finger command, but those are visible only after they’ve done the previous [public_html] exercise, which sets up the file permissions.

[number-function]

Calculate (in automated fashion) how many exercises there are in this HTML document.

Tools to get it done: this address with .md appended, curl -L, grep, pipe | and wc.

Hint: exercises are marked by the [...].

PS. don’t sweat it, this was the last exercise! (and pretty tough one, too)