CSC111 Lab 4
This lab deals with Linux Commands, for-loops, and string operations.
Playing with Linux
Copying Files
- Login to beowulf with your 111c-xx account.
- Execute the following commands at the Linux prompt:
getcopy dummy3.py
backupfiles
- It will copy the file dummy3.py from your instructor's account to your home directory, and the second line will make backup copies of your files (in case you inadvertently lose some of them during this exercise).
- The file dummy3.py is a simple python program you will be playing with. Verify that you do have this file in your directory:
ls -l (that's ell ess minus ell)
- The -l switch makes the ls command generate a "long" listing, with the date you last modified the files.
- Run the dummy3.py program to verify that it works.
python dummy3.py
- Assume that this program is actually a program you have been developping. Let's assume that it is working just the way you want and you would like to make a copy of it to save its current state before you continue editing it. Here's how you would do it:
cp dummy3.py dummy3.py.good
- This copies dummy3.py into a new file called dummy3.py.good. Use the ls command to see that you have this new file in your directory.
- Now edit dummy3.py, and modify it, adding errors in the code (Go ahead, don't be afraid!).
- Try to run it with Python again. It should crash with some errors. Now, imagine that you just cannot remember what you changed in the program, and that you want to return to the last working version. Then type:
cp dummy3.py.good dummy3.py
- Accept to overwrite the original by typing y. Now, dump the contents of the file on the screen to see if it contains the original:
cat dummy3.py
- Then run it:
python dummy3.py
- You now have the basics for making backup copies of your files.
Deleting files
To delete files we use the rm (for remove) command. Let's remove the dummy3.py program from your directory:
rm dummy3.py
Check with the ls command that the file is now gone from your directory. Get a new copy of it from my account with the getcopy command:
getcopy dummy3.py
Do an ls to see it there. You should also see dummy3.py~ and dummy3.py.good. By the way the dummy3.py~ file is the way the file was before you last edited it with emacs. Emacs creates this file automatically and appends a ~ sign to the end. Let's remove all the dummy3 files:
rm dummy3*
The * (star) character is called a wild-character, and matches any word. So all the files whose name starts with dummy3 will be targetted for deletion. Verify afterward with ls that all the dummy3 files are gone. Another Linux command
Ever wonder who else in the class was working with python? Simple with Linux: the w command, for WHO, will tell you. Go ahead and type w at the Linux prompt to find out... The right hand-side of the listing will even tell you what the users are actually doing. "-bin/tcsh" is the name of the program in Linux that displays the prompt to the user and executes the commands (such as ls, or cp, etc.