Linux Tutorial

The Linux operating system is a popular, open-source alternative to Windows. Many software companies, especially startups, run Linux, as do many governments world-wide.

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

Running Programs

With Linux, you can use either a graphical user interface (GUI) or a command-line terminal. 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 Home). If you click on that icon, you'll see the sub-folders and files you have in a File Manager window. Some have been setup for you. You'll also want to create some sub-folders yourself-- you can do this by selecting File | Create Folder.

Text Editors

Under Applications | Accessories, there are some file editing programs like KWrite and the gEdit 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 textual commands to the operating system. 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.

lists the files in your current directory.
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'.
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.
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.

The command-line terminal allows you to do similar operations as the GUI. Open up a terminal window and follow the instructions below. Do not type the $ in front of each command, that represents the Linux prompt:

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.

2. You can get to the new sub-directory by typing:

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

    $ cd ..

.. means go up in the directory hierarchy.

4. Now check the GUI to see if your commands have really changed things. Click on your Home Icon. It should now list an icon for the labProjects folder.

5. Open the gedit Text Editor at Applications | Accessories | Text Edit. Use the editor to create a file with a single Python command:

    print 'hello'

Save the file in your home folder and named it ''

6.  Back In the terminal window, type:

     $ ls

This should list the files in your home directory, including ''

7. Copy the file into the labProjects sub-folder. Enter:
    $ cp labProjects/.

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

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

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

    $ cd ..
    $ ls

10. 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 labProjects/
    $ ls                                           
    $ cd labProjects
    $ ls                                           

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

11. Remove

    $ rm