CSE 271 Lab 2: Using UNIX part 2

Announcements

As always, don't forget how to learn about the commands described.

Connect and log into a sun

Use an ssh client to connect to sunlab.cse.lehigh.edu (which will randomly choose a sun for you). If desired, you could also ssh directly to a sun using its name such as antares, ganymede, metis, tethys, titania.

ssh, scp, sftp

As you know, ssh provides a secure mechanism to connect from one machine to another and start a shell. ssh also provides the foundation for a few other commands, such as scp and sftp, which you can think of as secure copy and secure ftp (file transfer protocol). The suns have each of these installed. You can run ssh at a shell to connect to another sun if you like, e.g.:

So, the above demonstrates how I used ssh to connect from tethys to umbria and get a shell running there. Since I had not done so previously, ssh warned me that the secure fingerprint provided by umbria was not one that I had seen (and accepted before), and asks me to continue. It won't ask me that again (unless umbria's fingerprint were to change for some reason).

The scp and sftp allow you to securely copy one (scp) or more (sftp) files from one machine to another. Since I have two user accounts, I could use scp to copy files from one to another, such as:

We can use sftp to allow us to connect and use ftp-like commands to get and put files to a remote host, such as some of the university machines to which you have access.

So here I used sftp to copy a file from my current account (dot-emacs) to my university afs space by connecting to an IBM workstation in Christmas-Saucon running linux. (You can find out where more such workstations are here.

Changing your password

You were given an initial password to access your CSE account. For increased security, it is often a good idea to periodically change it. Your university account requires you to change it every six months, but the CSE accounts are not so strict. When you do want to change it, you'll use the passwd command, as in:

Note that it requires that you know your old password first, and will prevent you from re-using passwords that are too similar. The best passwords are often those that are abbreviations for something that is funny or offensive (to make it easy to remember).

Disk usage and quota

As you continue to use your CSE account for multiple classes and perhaps email and web pages, too, you will be using more and more storage. A new user's storage allocation is small, but you can request additional storage easily if needed (email to help).

There are two UNIX commands that can help you understand how much disk space you are using. The first is du, which stands for disk usage. By default it tells you how many blocks of disk you are using in the current directory and within any subdirectories. A block in Solaris is 512 bytes, but the -h option will convert it to something more useful. Try it out on your account and see how much storage you are currently using.

The second command is quota -v. It shows how much total storage you have used on the filesystem and what your quota is.

So from this I can see that I am using 20MB in my home directory and my limit is 50 megabytes. The hard limit of 75MB allows me to temporarily (for a few days) use more than the 50MB if needed. If I try to create files that sum to more than 75MB, they will fail. See what your quota is.

The grep command

Sometimes it is useful to find the lines of a file that match some pattern. A very simple use is to find the lines in a program that call a function. grep is a great command to use for this. For example, I can find every line that contains the string "print" in mycat.c:

I could equivalently have typed grep print < mycat.c. When used this way, we can think of grep as a filter. It is reading from standard input and filtering the content in some way and sending the remaining text to standard output.

Writing a filter

For the last task of the morning, let's write our own very simple filter. This program will be somewhat similar to our mycat program. Your task is to write a simple character filter to collapse extra white space in text files. The filter should change each tab character ('\t') to a space and collapse a series of two or more spaces into a single space. As a Unix filter, it should read its input from stdin and write its output to stdout. Do not use character arrays or strings for this program.

As an example usage using input redirection, assume the contents of the sample input file are as shown.

and once you have successfully written your collapse.c program, you can compile and run it as:

Last revised: 25 January 2007, Prof. Davison.