CMSC 201

Lab 1: Introduction to Unix and Emacs

Unix/Linux Commands

As described in the previous slide, you may run linux on your local workstation or log onto gl.umbc.edu. For today's lab we're going to login as you would from home.

You'll have to use the ssh command to log into gl.umbc.edu.

  1. Right-click on the desktop background to open a terminal.
  2. At the linux shell, type ssh gl.umbc.edu.
  3. Then type your password to login.

When you first login to your account you will be in your home directory. To see the names of the directories and files that are already in your home directory, type ls:

linux3[1]% ls
Desktop  Mail  mail
linux3[2]%

ls stands for ``list'', it lists the items in the current directory. You should see mail and possibly some other files and directories. Directories are like folders in Windows. You should create directories as needed to keep your files orderly. Make a directory called 201 by typing the command mkdir 201. Then, type ls and you'll see the name of the directory you've just created.

linux3[2]% mkdir 201
linux3[3]% ls
201  Desktop  Mail  mail
linux3[4]%

To change into the 201 directory, type cd 201. Now type ls.

linux3[4]% cd 201
linux3[5]% ls
linux3[6]%

Notice ls did not give any output. That means that there are no files in this directory. Now make a directory for your homeworks in this 201 directory, by typing
mkdir homeworks. Then type ls to see the results.

linux3[6]% mkdir homeworks
linux3[7]% ls
homeworks
linux3[8]%  

Since there will be 8 homeworks, we should make a directory for each of them in the homeworks directory. First we'll have to change into the homeworks directory.

linux3[8]% cd homeworks
linux3[9]% mkdir hw1
linux3[10]% mkdir hw2
linux3[11]% mkdir hw3
linux3[12]% mkdir hw4
linux3[13]% mkdir hw5
linux3[14]% mkdir hw6
linux3[15]% mkdir hw7
linux3[16]% mkdir hw8
linux3[17]%  ls
hw1  hw2  hw3  hw4  hw5  hw6  hw7  hw8
linux3[18]%  

Now we want to go back up to the 201 directory. Typing cd .. will move us up one level in the directory tree, which will take us up to the 201 directory. We'll want to make a projects directory too.

linux3[18]% cd ..
linux3[19]% mkdir projects
linux3[20]% ls
homeworks   projects
linux3[21]%

The cp command allows you to make a copy of a file or directory and give it a different name. Let's make a copy of this file and call it copy.py Type cp original.py copy.py Then, type ls to see that you have two files now, one called original.py and one called copy.py

linux3[23]% cp original.py copy.py
linux3[24]% ls
copy.py homeworks   original.py   projects
linux3[25]%

The mv command allows you to move a file and/or change a file's name.
Type mv copy.py same.py. Then, type ls to see that the files are now called original.py and same.py.

linux3[25]% mv copy.py same.py
linux3[26]% ls
homeworks   original.py   projects   same.py
linux3[27]%

The rm command allows us to remove or delete a file. Type rm same.py You may be prompted to make sure that you really do want to delete this file. Answer with a lower case y. If you then type ls, you will notice that the file same.py no longer exists.

linux3[27]% rm same.py
rm: remove `same.py'? y
linux3[28]% ls
homeworks   original.py   projects
linux3[29]%

We have used the cd command before to move into subdirectories by typing cd and the directory name. We've used cd with the .. to move up to the parent directory (up one level). Using the cd command alone, without a directory name following it or the .., will take you to your home directory. Type cd and then ls and you should recognize the files that are in your home directory.

linux3[29]% cd
linux3[30]% ls
201  Desktop  Mail  mail
linux3[31]%

The pwd command tells you your current directory. It stands for ``print the working directory''. Type pwd and you will see the full path to your home directory. Mine is /afs/umbc.edu/users/s/l/slupoli/home and yours will be similar.

linux3[31]% pwd
/afs/umbc.edu/users/j/m/jmccla3/home/
linux3[32]%

Now let's change directory into our homeworks directory by typing
cd 201/homeworks Typing pwd will reveal what the full path to this directory is
/afs/umbc.edu/users/ ... /home/201/homeworks

linux3[32]% cd 201/homeworks
linux3[33]% pwd
/afs/umbc.edu/users/j/m/jmccla3/home/201/homeworks
linux3[34]%

Once you understand how to move around, you can give more complicated commands like, for example,
cp fileheader.py ../proj2/