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.
You’re probably already logged in, so this may be unneeded, but the initial login screen on the lab machines should look something like this:
you should have already been given a CS username and password (if not, see your professor)
just enter your CS username and password
Note: these computers are different from the ITS computers on campus. We run linux on these computers, and only students taking CS have accounts on these computers (which is why your CS password is different from your ITS password)
if you’ve forgotten your password, try our self-service password reset page
if you still have trouble logging in, or any questions about the CS computers, send an email to local-staff at cs.swarthmore.edu
The default window manager we use is xfce. Once you log in, the screen should look something like this:
We will run various unix commands in the terminal window.
Open up a terminal window with a single click on the terminal icon in the dock.
After you open a terminal, your screen will look something like this:
If you didn’t already change your password on the first day of class, or if you just want to change it again:
passwdcommand in a terminal window
it will ask for your current password once and a new password twice
passwdprogram doesn’t show any stars (****'s) when you type your passwords (see screenshot below)
please protect your CS account with a good password!
CS passwords should be:
8 or more characters in length
contain mixed case letters
contain at least one non-alphabetic character
Note: if you ever forget your password, you can use our self-service password reset page: https://password.cs.swarthmore.edu
directories (aka, folders)
Your home directory (some people call them folders) is part of a tree-like structure:
the full path to hpotter1’s home directory is
the full path to hpotter1’s 01 directory is
you can use the
pwdcommand to print your working directory (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 hpotter1, or ssquarp2). When you first
log in and open up a new terminal, 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/hpotter1/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/hpotter1
Note: 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! And anywhere it says username, please type in your user name, like hpotter1 or gwashin2, etc.
$ 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.
atom is probably the easiest to learn, and you should
try that out the first week of class. You can try it out by just
atom in a terminal window.
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
vim and learning the basics.
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 mypog.py $ ls $ mv mypog.py myprog.py $ ls $ cat myprog.py $ rm myprog.py
The above 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'.
logging in from home
Your Swarthmore College ID cards have a prox tag in them. If you are taking a CS course this semester, your ID should allow you to open the lab doors at any time, day or night, so you can work in the CS labs as much as you want. And we have a lab in the basement of Clothier (C16) that you can use, as well as the three in the science center (238, 240, 256).
If you don’t want to come to the labs, you can still connect to our
ssh, which stands for Secure Shell.
ssh should already be installed. All you should have to do is
open up a Terminal and type
ssh -Y email@example.com
(substituting for your username, like hpotter1).
For PCs, you will need a secure shell client, like Putty. On your PC, download and install the putty.exe file and then run it and connect to lab.cs.swarthmore.edu
More information about remote logins:
Don’t forget to logout when you are done. It’s best if you quit all applications first, like Browsers, Terminals, and Editors.
After quitting all applications, single-click the in the dock and then click the "Log Out" button:
unix commands summary
cd— change directory
ls— list your files
pwd— print your working/current directory
mv— move/rename a file
rm— remove a file
passwd— change your password
examples of the above commands
In this example, the student’s username is hpotter1.
$ pwd /home/hpotter1 $ ls Desktop/ Documents/ cs21/ $ cd cs21 $ pwd /home/hpotter1/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 hpotter1 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 2019— prints out calendars
For more help documentation: https://www.cs.swarthmore.edu/newhelp
Any questions about the CS computers, please email local-staff at cs.swarthmore.edu