Homework: Get Acquained With Unix

Before doing the lab exercises on the fourth day of class, you should be prepared to be able to login to one of the systems and be familiar with some basics. You can do these exercises in your spare time from your office or home, so that you can easily start the lab exercises and focus on learning Perl.

  1. If you do not have an account on ada, visit the Howto Guide for instructions.
  2. Login to ada. (For additional details check here.) So, for example, if you are using ssh and your login name is mylogin, you would type:

    ssh mylogin@ada

    Once you've entered your password, you will be logged into ada.
  3. Print your working directory:


    which should output your home directory. On ada, that would be /g/home/mylogin.
  4. List the contents of your home directory:


    which should output a list of files, such as README.
  5. Get a detailed listing:

    ls -l

    Now, you'll see detailed information on each file, including permissions, ownership, file size, and modification date.
  6. List "hidden" files:

    ls -lA

    The list includes the "hidden" files, which are just the files which start with a period (dot files). These are usually the startup files, like .bashrc or .profile.
  7. View the README file:

    less README

    The less program shows you the contents of a file, page by page. Each time you hit the spacebar, it will scroll down one page. You can also use the arrow keys, the Page Up and Page Down keys, etc.. To quit, just hit the "q" key. For help on other key commands, hit "h".
  8. Change your working directory:

    cd /scratch/user/mylogin

    This will change to your scratch directory. Confirm this by using the pwd command. You can list the files there as well. There should be a directory called tmp there, along with any other files you created.
  9. Create a new directory:

    mkdir xyz123

    List the contents again with ls -l to see this new subdirectory.
  10. Change your working directory again:

    cd xyz123

    This will change to the directory you just created. Notice that without any slashes ("/") to start the name of the directory xyz123, the cd command starts looking in the current working directory. This is called a relative path. So, from your scratch directory, "xyz123" is the same as "/scratch/user/mylogin/xyz123". The first form is a relative path and the second is an absolute path (sometimes referred to as a full path).
  11. Now that you're in the xyz123 subdirectory, create a file called simple.txt. First, pick which editor you will use. (For details on text editor, see check here.) Assuming you are on ada and you want to use nano, you would type:

    nano simple.txt

    Your terminal screen will now be cleared and the top line will indicate "File: simple.txt". At the bottom of the window, it will have a list of the key commands you can use. For example: "^X Exit" means that by holding the "Control" key and hitting "x", you will exit the editor.
  12. Type a few sentences and then save the file using the "^O" key command (write out). Then, use the "^X" key command (exit) to go back to your normal terminal prompt.
  13. List the directory:

    ls -l

    You should see a line for the new file, simple.txt, which shows who owns it (you), the group owner (users), the number of bytes in the file, the the date it was last changed.
  14. View your file:

    less simple.txt

    Since it's a short file, there are not multiple pages to go through, just the one. To quit, just hit the spacebar or "q" key.
  15. View your file with cat:

    cat simple.txt

    This simply outputs the file without pausing. If you use cat on a large file, like README, the hundreds of lines will scroll past very quickly.
  16. Rename your file from simple.txt to other.txt:

    mv simple.txt other.txt

    List your directory to see that the name has changed. If you try to use less or cat on simple.txt, you'll get an error.
  17. Make a copy of other.txt, called something.txt:

    cp other.txt something.txt

    List your directory to see that you now have two files.
  18. Edit something.txt:

    nano something.txt

    Add a few new lines to it. Save and quit. List the files again to verify that the size has changed.
  19. View both files:

    less other.txt something.txt

    Hit the spacebar to go from one file to the next, or use the "q" key to quit.
  20. Remove other.txt:

    rm -i other.txt

    The -i option is for "interactive", which means you will be asked to confirm the deletion. It is good practice to use this option to avoid accidentally deleting files. List your directory again to see there is only one file remaining.
  21. Remove something.txt:

    rm -i something.txt

    Now your subdirectory xyz123 should be empty.
  22. Change back to the directory above:

    cd ..

    Confirm that you are in /scratch/mylogin with the pwd command.
  23. Remove the xyz123 directory:

    rmdir xyz123

    If you have any files or subdirectories in xyz123, you can't remove it. In this case, you should have no problems.
  24. Logout of ada:


    You can also use "^D" (control-d).

These simple exercises should be enough for you to be able to do the laboratory exercises. To learn more about basic Unix commands, go to the New User Information page, and look under the Getting Started section for links to additional information. Read the Introduction to Unix and Basic Unix Commands pages. Experiment with the commands while you are logged into the system.