Tutorial #2: Linux Tools


APT (Advanced Package Tools)

I. Warmup

Log into your Linux machine and start a Terminal (Application - Accessories - Terminal). The prompt should look something like rong@sjtu-rong:~$, which is composed of your Username and Hostname:

rong@sjtu-rong:~$

When you log in, the default user is just an unprivileged user like "rong". Before using APT commands to install softwares, you must use the su command to be the privileged user, named "root".

rong@sjtu-rong:~$ su
Password: (enter the password here)

The prompt would be look something like root@sjtu-rong:~$:

root@sjtu-rong:~$

II. Looking Around

The APT command depands on the local software information cache from source server, so you must set correct address of source server in the APT configuration file "/etc/apt/sources.list", which should look like the following content:

(you could use the cat to output the file, or use vim to edit it.)
$ cat /etc/apt/sources.list
...
deb http://ftp.sjtu.edu.cn/debian/ squeeze main
deb http://ftp.sjtu.edu.cn/debian/ squeeze main
...

To learn more about the configuration file, you can read the manual by typing man sources.list.

$ man sources.list (read the man page)

Now you could use the apt-get update command to link the source server and update the local software information cache.

$ apt-get update
...
Reading package lists... Done

III. Install htop

The software htop is a visual version of the top command, which provides a real-time view of running system, including a system summary informantions and a list of tasks currently being managed by Linux kernel.

$ top (type "q" to exit)

Please try to run htop first to make sure it has not been installed

$ htop

If it has been installed, you could use apt-get command with the remove option and package name htop to uninstall it.

$ apt-get remove htop

The first step to install htop is find the package name using the apt-cache command with the search option

$ apt-cache search htop
htop - interactive processes viewer

Now you coud use apt-get command with the install option and package name htop to install software htop.

$ apt-get install htop

Now you coud use htop command to show the system information.

$ htop

To learn more about the htop software, you can read the manual by typing man htop.



SVN (Subverison)

I. Warmup

To make sure that the SVN tools has been installed on your system:

$ man svn

If it has not been installed, you could use apt-get command with the install option and package name subversion to install it.

$ apt-get install subversion

II. Basic Operations

We provide the lab0 to help you to be familiar with the SVN operations, which you need to use in the following labs.

The first step is to exit the root user and change to your home directory.

$ exit
$ cd

Now you could use the svn command with the chechout(co) option to get your svn folder from server to your local directory icslabs. The host name of svn server is ipads.se.sjtu.edu.cn, and the path should look like /ics-se12/ics5120379001, which is composed of abbr. of semester (ics-se112/tt>) and your svn-id (ics + student-id).

$ svn co svn://ipads.se.sjtu.edu.cn/ics-se12/ics5120379001 icslabs --username=ics5120379001
(replace "5120379001" with the your own student-id)
Password for 'ics5120379001': (enter the password here)
A    icslabs/lab0
A    icslabs/lab0/helloworld.c
A    icslabs/lab0/README
Checked out revision 3.

Change your current directory to icslabs directory, which is your top-level svn directory. You could use the ls -la to show the current content of the icslabs folder. The output should include a lab0 directory and a .svn directory, the former includes all your lab0 files and the latter is used by svn tools (e.g. save your svn-id and passwd). Note: all svn operations must be run within the directory checkouted from svn server and sub-directories, like icslabs.

$ cd icslabs
$ ls -la

You could use the svn command with the update option in your top-level svn directory(icslabs) to get latest labs after we publish them on svn server.

$ svn update

Change your current directory to lab0, and start to finish your lab0 tasks. You should read the README file first, which usually includes the introduction to this lab.

$ cd lab0
$ vim README

III. Lab0

The first task is to finish the C program helloworld. We provide the sketch code in the file helloword.c. The program simply outputs a "hell world!" string on screen. You should modify the helloword.c, and compile it using the gcc command.

$ vim helloworld.c
... (finish the source code)
$ gcc -o helloworld helloworld.c
$ ./helloworld
Hello world!
$

After you finish the program, you could use the svn command with the status option to check the file status. To learn more about the svn status command, you can read the help file by typing svn status --help. Now, you need to submit your updated code file to svn server using the svn command with the commit(ci) option and the file name. You also could add some comments to this commit operation using --message="blablabla". Note: you don't need to subimit the executable file helloworld

$ svn status
M    helloworld.c (The symbol 'M' means the file has been modified, and not be commited)
?    helloworld (The symbol '?' means the file doesn't exist in svn server)
$ svn ci helloworld.c --message="finish helloworld program."
Sending    helloworld.c
Transmitting file data .
Committed revision 4.
$ rm helloworld
$ svn status
(Output nothing means all files are equal to the svn server)

The second task is to submit your answers for the last four questions in Linux Shell. You need to create a new file named "answer.txt", and write the answer of each question in 1 line in the file.

$ vim answer.txt
...
$ svn status
?    answer.txt (The symbol '?' means the file doesn't exist in svn server)

After you finish the file, you should add the new file to svn server using the svn command with the add option and the file name, and commit it like previous operations.

$ svn add answer.txt
$ svn status
A    answer.txt (The symbol 'A' means the file is new, and not be commited)
$ svn ci answer.txt --message="finish linux shell questions."
Adding    answer.txt
Transmitting file data .
Committed revision 5.

Finally, if you want to confirm that all your works have been updated to svn server, you could use svn status to compare your local contents with the server's.




Go to Top // ICS Home Page
Questions or comments regarding ICS course? Send e-mail to the course Staffs or TAs.
Last updated: Wed Mar 3 2013