CS 151 - Introduction to Data Structures
Lab 2
Unix
Using Unix
Some important UNIX commands:
- cd
Change directory
Example: cd cs206 (change to the directory cs206) (Note that this will probably not work as you do not have a cs206 directory.)
Example: cd .. (change to the directory one above where you are, for instance is you are in
/home/xena/cs206, then cd .. would put you in /home/xena
Example: cd with no argument. This returns you to your home directory
password
- ls
Display a list of all the files in the directory. It is very common to use the ls command immediately after cd.
Example: ls list the files in the current directory
Example: ls cs206 list the files in the directory cs206 (if it exists)
- mkdir
Create a directory
Example: mkdir cs206 make a directory named cs206 Actually do this in your home directory. To be sure you are in your home directory enter the command cd (I often get back to my home directory when I mean to be somewhere else. Annoying, but at least then I know where I am)
- pwd
Displays the current working directory. In other words this command shows you where you are.
- cp
Copy a file
Example cp a b make a copy of the file name "a" in the currect directory into a file named "b" in the current directory. Note that is "b" existed before the cp command, then it will be overwritten
cp /home/gtowell/Public/151/L02/microtrades.txt m.txt make a copy of the file "microtrades.txt from the directory "/home/gtowell/Public/151/L02/" into the currect directory in a file named m.txt
Lots of riffs on this general idea are possible with cp
- mv
Move (and/or) rename a file
Example: mv a b rename the file named "a" to "b". As with cp, if there was a file nmed "b", it will be overwritten.
mv /home/YOU/aa aa Move a file named "aa" from your home directory to the current directory and keep that file named "aa".
- rm
remove a file
Example: rm aa Permanently delete the file "aa"
Execute the above unix commands, put answers to the questions to their right
cd | What directory are you in? | |
| What is the contents of this directory? | |
cd / | What directory are you in? | |
| What is the contents of this directory? | |
cd ~ | What directory are you in? | |
| What is the contents of this directory? | |
cd /home/YOU | (Replace YOU with your login name) What directory are you in? | |
| What is the difference between this command and the previous one? | |
ls /home/gtowell/Public/206 | What did this command do? | |
A good understanding of these few UNIX commands is about all you need to this course. (Many Unix users know little more than these.)
Lets finish this lab by copying files between your computer and the CS Unix computer. The command to copy between machines is scp. "scp" is "secure copy"; it basically extends the cp command so it can be used between machines.
First make a directory on your machine for this lab. The directory should be within the cs151 directory. (use cd and mkdir as needed).
Next, move into the diretcory you just made
Copy a file from Linux to your local directory. (Note that if you are doing this all from within linux you can use cp rather than scp (ask me))
scp YOUR_CS_LOGIN@powerpuff.cs.brynmawr.edu:/home/gtowell/Public/151/L02/microtrades.txt localmicro.txt
You will need to enter your password. This command copies a file from my Public directory onto your computer. You will do many such copies this semester. You will learn to love (or hate) ssh and scp.
Edit the file using your favorite text editor (e.g. TextEdit on Mac, Notepad on Windows or you can use VSC). The major point here is just to find this file on your machine using a standard GUI tool.
Finally, copy this file back to Unix, but into your directory.
scp localmicro.txt YOUR_CS_NAME@powerpuff.cs.brynmawr.edu:cs206/lab02/remotemicro.txt
You should be able to use a combination of ssh, cd and ls to confirm that the file remotemicro.txt exists in the in the Unix directory structure you created earlier.
Send email to gtowell151@cs.brynmawr.edu with the following:
- A completed table for the questions in the UNIX section
The easiest way to do this might be to use your phone and take pictures of the completed table and your screen showing answers. Alternately, if you typed your enswers, just send them. These are just suggestions for how you could turn things in. Feel free to be creative. All I require is legibility.