* 1 *
The exercises this week are dedicated to the Linux command line using your Linux account at the student server studssh.cs.hioa.no or any other server running Linux. If you are not able to access this server yet, use the Linux server at UiO, login.ifi.uio.no with the username and password you got from the University of Oslo. For those of you who are familiar to Linux command line, there are some extra challenges and the bottom of this page. Finally you should log on to, explore and get used to your network of virtual machines. .
Complete the following exercises by logging in to your account at the server studssh.cs.hioa.no(or login.ifi.uio.no) from any of the Windows PC's using putty and the same username and password as for Windows.
Document the commands your run and the output that appears on the screen.
You may want to use the script-command to do this. Where there is a question, answer it. NB: "print" refers
to displaying something in your terminal, not actually printing it out
(some more exercises for a Unix crash course are located at
http://www.cs.hioa.no/~haugerud/unix/ if you need more practice.)
Use Matt Disneys Linux
crash course as an instructional reference. Another resource is
Mark Burgess book:
The unix programming environment
The assignment should be submitted individually. Submit using fronter(wait till your fronter room is available).
Write a short report answering the questions in a text file.
Answer all the questions and submit them using fronter(log on at
http://www.hioa.no/fronter and choose engelsk(english) as language),
using the folder "Assignment 1". Any format is
accepted, preferably PDF or ascii-text. If you submit using a editable
format, like ascii, odt or doc, you may receive comments within the
text from the teachers. Submit the complete assignment in a single document.
- Read the manual page for the script command by man script.
If you run the command script week1.txt everything you type and its output will
be stored in the file week1.txt. Find out how to stop the script session.
- Access the manual page for the ls command. What does the -l option do?
- Print your working directory (your current location in the filesystem)
using the command pwd.
- Change to the root ( / ) directory using
cd. Confirm your location using pwd.
- Change back to your home directory.
- Go to the directory /usr/bin using absolute path.
- Go to your home directory. The go to the directory /usr/bin using relative path.
- Run ls. Now run ls -a. What is the
difference in these two commands?
- Make a new directory using the command mkdir myfolder. Verify
that it exists using one or more of the commands you learned earlier.
- Remove the directory you just created using the command rmdir myfolder.
Verify that it no longer exists.
- Create a new file by using the jed editor: jed myfile. (If jed is not installed, use emacs, pico or nano). Type "Hello world!"
in your text document. Be sure to save it.
- Use the utility cat to view the new file you just created.
Use the utility cat to view the file ~dstud/twocolpaper.tex.
What do you think the ~ represents?
- Now use the utility less to view the same file. What is the difference between
cat and less?
- Copy that file to your home directory using the command cp.
- Create a new directory called testdir. Confirm that it exists.
- Move the twocolpaper.tex file to your new directory using
the utility mv. Confirm that the move worked.
- Use the utility rmdir to remove the testdir directory. Why does
that not work? What command will enable you to remove that directory?
- Use the command echo hello to print out the word hello.
- Use the same command, but add the following to create a file containing the word hello: "> hellofile". Confirm that your new file contains the appropriate text.
- Use the command "echo" to print the value of the SHELL variable.
- Assign your first name to the variable NAME. Use echo to print it.
- Use the editor jed to create a new file with some text of your choice: jed mytextfile.
- Now run the command jed MyTextFile. Where are the contents of the file you created in the previous step? What happened?
- Determine how to display the date for the Orthodox Easter using the ncal. Put this command in a text file called myscript. Run sh myscript. Congratulations, you have written your first shell script!
- Create a shell script blah.bash which does the following things:
- Assign "/etc/default" to a variable
- Using ls and your new variable, output the list of files in /etc/default to the file blah.txt.
- Change the file permissions of blah.bash so that the
owner has all permission to to anything (and can run it by $
./blah.bash), the group may read and run it and all others may
just read the file.
- Using the output from /sbin/ifconfig,
assign the IP-address of studssh to the variable $IP.
Find which program is started when you give the
commands ls. (hint: Try $ type ls).
Edit a file in your home directory with jed
and call it ls. Write in the following shell-script:
Make the script runnable with the command chmod 755 ls.
Write the command
ls in the shell. Is it "your" or the system ls that is
executed? Add the line
echo This is my ls script. to your ls.
run the ls-command again and try to make the system list the files
with your script.
- Make your own traceroute-command by writing a short bash script which utilizes
the response to ping-packets with an increasing TTL-value, starting from one:
ping -w 1 -c 1 -t 1 vg.no | grep icmp
The output could be similar to this
studssh$ mytrace vg.no
1 From cadeler30-gw.uninett.no (126.96.36.199) icmp_seq=1 Time to live exceeded
2 From pil52-gw.uninett.no (188.8.131.52) icmp_seq=1 Time to live exceeded
3 From stolav-gw.uninett.no (184.108.40.206) icmp_seq=1 Time to live exceeded
4 From ge-0-2-0.br4.osls.no.catchbone.net (220.127.116.11) icmp_seq=1 Time to live exceeded
5 From ge-0-1-1.cr1.osls.no.catchbone.net (18.104.22.168) icmp_seq=1 Time to live exceeded
6 From v99.rs2.sand.no.catchbone.net (22.214.171.124) icmp_seq=1 Time to live exceeded
7 From 126.96.36.199 icmp_seq=1 Time to live exceeded
8 64 bytes from 188.8.131.52: icmp_seq=1 ttl=249 time=1.31 ms