These pages are meant for students new to the SwatCS computers.
After working through the sections in the Table of Contents on the left, you should feel comfortable using some basic unix commands in the terminal window.
And don’t feel like you have to remember it all after one session. Feel free to return to these pages anytime to refresh or learn more. The more comfortable you are with unix commands in the terminal, the more efficient you will be getting your CS labs done!
UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.
passwords for new users
New users need to set their initial CS account password. If you haven’t already, go to our self-service password app and click the "Click to Request Reset" link near the bottom of the page. From that link you should be able to set your initial CS password (enter your username, click Request Password Reset, check your Swarthmore email, etc).
If you have any trouble setting your password, see our new user help page for detailed instructions and screenshots.
The CS computers are different from the ITS computers on campus. We run linux on these computers, and only students taking Computer Science (CS) have accounts on these computers (which is why your CS password should be different from your Swarthmore/ITS account password).
Once you have your CS account password, you can use
ssh to access the
ssh stands for secure shell, and is a program that
encrypts all communication between your home computer and the CS computers.
It runs from a terminal window and is probably already installed on your
computer (if not, see our
remote access help page).
On Macs, search for the Terminal application and start it. On Windows, either search for the PowerShell application or install putty and start it. And try to keep the browser window and the terminal window open and side-by-side for the rest of this tutorial, so you can try out commands as we go!
ssh, enter the following command in the Terminal
or PowerShell/putty window, replacing username with your username (e.g.,
ssh -Y firstname.lastname@example.org
The first time you connect with
ssh it will ask "are you sure you
want to continue connecting (yes/no)?", like this:
ssh -Y email@example.com The authenticity of host 'cslab.cs.swarthmore.edu (18.104.22.168)' can't be established. ECDSA key fingerprint is SHA256:KDki/m7vRcdU4J99pfUd2a9dQ+xEbXR4ERZx4gW7gwU. Are you sure you want to continue connecting (yes/no)?
Answer "yes" to this question (assuming the fingerprint matches!) and your computer will store that key fingerprint so it knows it is always connecting to the correct computer.
Finally, you should be prompted for your CS password, and, if correct, be logged in to one of our CS computers. Here’s an example of what you might see:
ssh -Y firstname.lastname@example.org Password: Welcome to: macaw Ubuntu 20.04 focal macaw[~]$
In the above example, the user (dduck1) is logged in to a computer called
macaw. You may get a different computer. Many of our computers have bird names
(dodo, loon, hawk, etc). And the
macaw[~]$ part is the unix terminal prompt.
That’s where we will type all unix commands discussed below.
If you have any trouble getting logged in, or any questions about the CS computers, send us an email at sysadmins @ cs.swarthmore.edu and we will be happy to help you.
directories (aka, folders)
Your home directory (some people call them folders) is part of a tree-like structure:
the full path to dduck1’s home directory (the red oval) is
the full path to dduck1’s 01 directory (the blue oval) is
you can use the
pwdcommand to print your working directory, or where in the tree you currently are
Try this example! And the dollar sign ($) below is just the unix prompt (yours might look slightly different). You don’t type the dollar sign, just everything after the dollar sign.
And when we say "run this command", we mean type it in a terminal window.
The above should display
/home/username, where username is your
actual CS username (like dduck1, or aturing7). When you first
log in, you are always in your home directory (
Try this example, too!. Let’s make a sub-directory called
testdir, just for testing:
$ mkdir testdir
mkdir command makes a new directory (there’s no output or anything
if the command worked).
In the next few sections we’ll see how to view our files and change into different directories, like the test directory we just made.
We use the
pwd commands to change directories and
display where we are.
$ pwd $ cd testdir $ pwd
pwd should display your home directory. Then
the change directory (
cd) command moves you one level down
in the tree, to your newly-created
testdir. And the last
pwd should display
Users new to UNIX are often confused by paths and directories. A
full path lists out all directories, from the root, like
/home/dduck1/cs21/labs/00. You can always use a full path,
but it’s sometimes quite long.
cd .. do? Try it and see if you can figure
out where it puts you in the directory tree (hint: use
If you use
cd .. enough times, you will get to the root of the
directory tree (slash or
$ cd .. $ pwd /home $ cd .. $ pwd / $ cd $ pwd /home/dduck1
You can always use
cd by itself to get back to your home
directory (see the last
cd in the above example).
listing your files
ls command is short for list.
You can use the
ls command to see your files and directories
(folders). You can also list out files in another directory
using the full path (with the slashes in it — see below).
Try these examples!
$ ls $ ls testdir
ls above displays a few files and directories in
your home directory. You don’t have much at this point (I think
it just shows
ls above displays everything in your
which is nothing at this point, since we just made that. In the next
section we will add some files to that directory.
Try these, too.
$ ls ~jk $ ls ~jk/inclass $ ls -l ~jk/inclass
ls above lists out the files of user
This is something you might do when copying files from your
professor. In the output of the first
ls command, you should
inclass/ entry. The slash at the end of
it is a directory.
ls above lists the files in the
~jk is shorthand for
The last example above uses the
-l (lower-case L) option, which
shows the long format for listing files. This shows extra info on the
files and directories, such as the owner (
jk) and size
of the file, and who has access to read and write the file.
In the next section we will copy the
hello.py file into
testdir, so we can view and edit the file.
cp command is used to copy a file.
The format of the command is
cp file newfile, and this
makes a copy of
For example, to make a backup copy of a file named
cp prog.py backup-prog.py
Try this! Let’s change into our
testdir directory and
then copy the
hello.py file from user
$ cd testdir $ cp /home/jk/inclass/hello.py hello.py $ pwd $ ls
pwd output should show you are in your
ls should now show you have a copy of
hello.py in your
Remember: if you’re ever lost, a simple
cd command will put you
back in your home directory (
One more to try! Copy over the
unix_commands file from
$ cp /scratch/usingunix/unix_commands . $ ls
Don’t forget the dot (.) at the end of that
Using a dot for the newfile part of the copy command is a
shortcut for "name the copy the same as the original file".
When you run
ls, you should now have a copy of the
In the next section we will see how to view the contents of a file.
Sometimes we want to edit or change a file, and sometimes we just want to see the contents of the file.
To see the contents of the file there are two unix commands:
cat command (short for concatenate) can be used to just dump the
contents of the file to the screen. If the file is large, the contents
may scroll off the top of the terminal.
cat command! If you are still in
testdir, run the
command on the two files we now have in there.
$ cat hello.py $ cat unix_commands
To view a file one page at a time, use the
$ less unix_commands
q to quit out of
less at any time.
There are a variety of text editors on our computers.
Some students use
atom, some use
and some use other text editors such as
Your class web page or instructor may suggest which editor
is best for your class.
For CS21 this semester (F20) we are using
atom is probably the easiest to learn, but somewhat tricky to
use if working remotely.
Students taking CS31 should learn
vim. There is a
vimtutor command which puts you into a file and teaches
you the basics of
vim. Your first lab (lab0) will have more
information on using and learning
rename or remove a file
mv command is used to move or rename a file.
The format of the move command is similar to the copy
mv file newfile. For example, to
rename a file from badname.py to goodname.py:
mv badname.py goodname.py
You can also move a file into a different directory with
mv file directoryname
rm command is used to remove a file.
For example, to remove a file called
Examples to try!
$ cp /scratch/usingunix/myprog.py mypppprog.py $ ls $ mv mypppprog.py myprog.py $ ls $ cat myprog.py $ rm myprog.py
The above commands should copy a file, then rename it, show the contents of the file, and finally remove it. When you remove the file, it will ask "remove myprog.py?", to which you can answer either 'y' or 'n'.
When you are done for the day you can log out of the terminal window
Ctrl-d (hold down the Ctrl key and then hit the d key).
unix commands summary
cd— change directory
ls— list your files
pwd— print your working/current directory
cp— copy a file
mv— move/rename a file
rm— remove a file
There are many more unix commands, but those are the basics you will need for any CS class.
For example, you can change your password using our
self-service password app, but
there is also a
passwd command that allows you to change your
password from within the terminal (see below).
examples of the above commands
In this example, the student’s username is dduck1.
$ pwd /home/dduck1 $ ls Desktop/ Documents/ cs21/ $ cd cs21 $ pwd /home/dduck1/cs21 $ ls inclass/ labs/ $ cd inclass/ $ ls w01-intro/ $ cd w01-intro/ $ ls welcome.py $ cp welcome.py w2.py $ ls w2.py welcome.py $ mv w2.py welcome2.py $ ls welcome.py welcome2.py $ rm welcome2.py rm: remove regular file welcome2.py? y $ ls welcome.py $ passwd Enter login(LDAP) password: New CompSci password: Retype new CompSci password: LDAP password information changed for dduck1 passwd: password updated successfully
other possibly-useful commands
a2ps myfile.py— prints myfile.py file to the lab printer
sharples— prints out the menus and hours
cal 2020— prints out calendars
For more help documentation: https://www.cs.swarthmore.edu/newhelp
Any questions about the CS computers, please email sysadmins at cs.swarthmore.edu