CSC15 Assignment 1: Using Fedora Linux
Due Thursday, 9/10
This lab is intended for you to:
- Learn basic Linux "survival skills"
- Learn how to enter and execute a couple of simple Python programs.
- Take a glimpse at the joys and pains of programming by modifying some
simple program lines.
Like most operating systems, Linux has graphical interface and many aspects
of it are self-explanatory. But there are several differences between
Linux and Windows and Macintosh computers that you need to understand.
- Once you've logged in, explore the desktop environment. Try to
bring up the Firefox web browser. Go to and bookmark the class homepage:
www.cs.hofstra.edu/~cscccl/csc15p
- Bring up a "terminal" window under "Applications" -> "System Tools".
This is the main interface you will use.
- The command prompt should read something like "$-sh-". Type "bash".. This gives you the prompt bash-3.00$.
- Type "pwd" - this command shows you what directory you're currently
in.
- Type "ls" - this command shows the contents of the current directory -
don't be surprised if there's nothing there - that's why we're here!
You can also use "dir" instead of "ls".
- Type "ls -a" - As with MS Windows, there are some hidden systems files
that are not usually visible. This command will display all files and
directories in the current directory.
- Type "ls -l" - This is the same as ls but gives you additional information
for each file and folder.
-
Basic Command Summary
- cd (directory name): change directory to named directory
cd .. : go to parent directory
cd /(path) : absolute directories begin with "/", the root
directory.
For example, if you are in directory /shared/csc/local,
typing "cd .." will take you to the /shared/csc directory.
- Typing "cd" by itself will take you to your home directory.
- pwd : tells you the current directory you're in.
- cp file1 file2 : copies the contents of file1 into a file called file2.
- ls : lists directory contents
- mkdir dirname : creates a new directory called dirname in the current directory
- mv file1 file2 : renames file1 into file2
- rm file1 : deletes file1
- rm -rf dirname : deletes the named directory and all its contents. Use with care!
- more filename : a quick way to view the contents of a text file.
Many of these operations can also be performed using the mouse in the
"file manager" window. However, you'll need to learn these commands if
you want to use the workstations remotely using telnet (I'll show
you how to do that later). Besides,
all serious computer users know them.
Let's now practice these commands (please do not deviate from instructions)
- Make sure you're in your home directory (type "cd")
- Type "mkdir csc15" - what does this do? You should creat a directory
for this class because you'll be using your account for other classes as well.
NOTE: if you're using one of the public accounts (adams01 - adams04), create a directory with your username instead, so you can keep your files separate.
- Type "cd csc15" - you're now in the directory you just created.
- Type "cd .." - you're back in the directory you were in before
- Go back into your csc15 directory
- Using Python in interactive mode.
Type "Python" to enter the interactive environment. Go to the "python
tutorial" link on the class homepage, and try to follow some of the
examples in section 3. You're encouraged to experiment. The interactive
mode allows you to quickly the range of valid syntax in Python.
When you're done, type Control-D to exit the Python interpreter.
Please note that while you're inside the python interpreter, you'll
see a prompt like ">>>". This is NOT where you can enter linux commands
like ls, cd, etc ... To do that, you need to be at the "shell" prompt
(like bash-3.00$).
- Time to write a program.
To do that you need to learn how to use an editor. A very powerful
(though less easy than MS word) editor used by programmers is "emacs"
- type "emacs &" - you'll see a window come up.
You should recognize a toolbar with
familiar buttons such as "file", "edit" and "help". Select "file" and
open a file called "firstprog.py"
- Type in the first program provided on the first attached sheet.
You do not have to type in all the comments marked with "#", but
put your name in comments at the top. Comments are lines that begin
with a "#".
- save it under the
name "firstprog.py" in your csc15 directory.
- Make sure you're in the
csc15 directory. Execute the program with "python firstprog.py"
Did you get any errors? If you did,
that means you had a typo while copying the program, so go back and
edit the program, save it, and try again.
- Change the program so that it prints your name 20 times instead of 10
- (harder). Change the program so that it prints your name 20 times BACKWARDS
- Quit emacs (click the "file" menu option)
- You can also start emacs and open a file at the same time by typing
emacs (filename) &.
The "&" is important: without it, you'll lose the ability to use the
terminal window while emacs is running.
- Now type in the second Python program, "secondprog.py"
You are to turn in the printouts of the two programs you typed in and
modified. Make sure the printouts have your names on it.
To print, type (in the same directory where the file resides)
lpr filename.
This will always print to the lazer printer in Adams 204.
Final Note: you are expected to remember what you learned today,
for these skills are required throughout the semester. Practice these
skills further on your own time.