Linux Tutorial

The Linux operating system is a popular, open-source alternative to Windows. Many software companies, especially startups, run Linux, and the operating system has also made in-roads in developing countries in Latin America.

This tutorial goes over the basics of Linux. The tutorial is geared for USF students and for helping new students setup their system for the semester.

Running Programs

With Linux, you can use either a graphical user interface or a command-line computing. When you login to a USF computer science account, you'll see the Linux GUI. You can run applications by choosing Applications in the top-left corner.

File Manager

Unlike a home PC or laptop, the lab computers are multi-user. So there may be others who have logged in remotely and are using the same computer you are using. In general, every user's workspace is separate and you don't have access to other user's files. But realize that they are there.

Your home directory will have your user name as part of its name and it should be represented with an icon on the Desktop (e.g. Wolber's Home). If you click on that icon, you'll see the sub-directories and files you have in a File Manager window. Some have been setup for you. You'll also want to create some subfolders yourself-- you can do this by selecting File | Create Folder.

Text Editors

Under Applications | Accessories, there are some file editing programs like KWrite and Text Editor. You can use these to write programs or anything else. You'll also learn more sophisticated software development environments later.

When you create a file, you'll save it somewhere within the file hierarchy rooted at your home directory.

Command-Line Terminal

Linux provides a 'command-line' interface which allows you to enter commands. You can get to the command-line by choosing

    Applications | System | Terminal Program.

The terminal window that appears will allow you to enter Linux commands.

File System

Where as Windows File Manager has a root named C:, Linux has a root directory named '/' (backslash). This is the root directory for all users on the shared file system. All other directories, including your home directory, are in the file tree below  /.
 
When you login to your CS account, your home directory is          /home/yourUserName 
 
For instance, Professor Wolber's is /home/wolber
 
You also have a web directory: /home/web/yourUserName

Files put into this directory are accessible to the public from any browser. You could put a homepage or other web pages here.

Linux Commands

Linux has hundreds of commands. In this tutorial, we'll just look at some of the most popular.

ls
lists the files in your current directory.
 
pwd
tells you where you currently are in the file system.
 
mkdir samples
creates a new sub-directory called 'samples'.
 
cd samples
changes you from the current directory to the sub-directory 'samples'.
 
cd
changes you from wherever you are to your home directory. For Wolber, this command is equivalent to typing:

    cd /wolber/home
 
cd ..
takes you up in the directory hierarchy, e.g., if you're in /home/wolber/programs, it will take you to /home/wolber.
 
passwd
changes your password. You should do this soon.
 
cp src dest
copies a file named src to a file name dest.
 
mv src dest
renames a file named src to new name dest. You can also use mv to move files to different directories.
 
rm file
removes a file (be careful)
 
rmdir directory
removes a directory (be even more careful)

using wildcards
Let's say you wanted to copy all the files in one directory to another directory. The asterisk is a wild card meaning 'all files'. So the command

    cp *.* /home/wolber/.

copies all the files with a name that matches *.* from the current directory to the directory /home/wolber. *.* can be read as anything followed by a dot followed by anything.

 The . after wolber/ means to give the copied files the same name as the original.

The command:

    cp *.txt /home/wolber.

copies all files with extension 'txt' to the directory /home/wolber.

Your Turn: Organize your file system for the semester.

You could do some of the following using the Linux windowing environment. We'll do it with command-line so you can learn the Linux commands. Open up a terminal window and follow the instructions below:

0. Go to your home directory

    cd

1. Create the  sub-folder 'labProjects' from your home directory.  Type:

    mkdir labProjects

You'll put all the programs you write in class here. You can get to the new sub-directory by typing:

    cd labProjects
   
You can get back to your home folder with:

    cd ..

.. means go up in the directory hierarchy.

2. Now let's check out how things have changed using the Linux Windowing environment instead of command-line. Click on your Home Icon. It should now list an icon for the labProjects folder.

3. Create a file with a text editor.

Select Applications in the upper left corner and choose Accessories | Text Editor. This is a simple what-you-see-is-what-you-get (wysiwyg) text editor.

    print 'hello'

in the file and save it as hello.py in your home directory. Python is touchy-- be sure and have the 'print hello' unindented to the far left in the file.



4. In the terminal window, enter the following:

    python hello.py

'hello' should appear. Congratulations, you just ran a python program.

5. List the files in a folder:
 
In the terminal window, type:

   ls

It should show "hello.py"
 
6. Copy the file into the labProjects sub-folder. Enter:
 
    cp hello.py labProjects/.

This means to copy hello.py (the source) into the sub-folder 'labProjects and keep the same file name ('.' means same name).

Navigate to the labProjects directory and make sure the file was copied.
     
    cd progams
    ls

Navigate back home and see that there is still a copy of hello.py there:

    cd ..
    ls

 
7. Move a file. Move is like copy, but it removes a file from its original location.

Move the file to the samples directory using the mv command.

    cd
    mv hello.py labProjects/hello2.py
    ls                                           
    cd labProjects
    ls                                           

You should no longer see hello.py with the first ls listing of your home folder. You should see both hello.py and hello2.py in the second ls listing (of labProjects).

8. Remove hello2.py

    rm hello2.py

 
 

Recent site activity