Lab #2, Friday 1/26

The purpose of this lab is to introduce you to basic Linux commands. With the prevalence of GUI-based operating systems, the command-line nature of Unix systems is somewhat less mainstream. However, there are many tasks that are much easier to complete in a Unix environment and "Headless" computing is also common in a client/server environment (not to mention, Unix familiarity makes you more employable). 

If you are familiar with Linux already this lab will be very short. If you are new to Linux it will take longer, so prepare accordingly!

We won’t really go scripting commands, but this tutorial and lab assignment will orient you to the basics of using Unix.  This basic knowledge will be necessary to complete your programming assignments.  You can also opt to use your own computer but you will need to install the necessary software.  If you have Windows 10 then in the Anniversary Update there is an Ubuntu bash shell!

Logging In

We covered logging in on the previous lab. As a brief re-cap, you need to use a ssh client.

Linux Commands

Read this tutorial from  You should read at least to the end of section 7 under "Learning the Shell" although it woudn't hurt to read more!

You can try commands out on transformer as you go.


Save your answers in a file. When you have everything answered go through them with the TA or instructor for credit.

  1. I have a public folder named CSCE_A211 on transformer in my home directory.  Change your current working directory to it with the command: cd  ~kjmock/CSCE_A211
    1. View the text file "programming_joke".  What is the punchline?
  2. You don't have file permissions to edit or save files in my folder. Make your own CSCE_A211 folder in your home directory and copy a file from my directory to yours with these commands:
    1. cd ~                             changes to your home directory
    2. mkdir CSCE_A211          makes a folder named CSCE_A211
    3. cp ~kjmock/CSCE_A211/reverseIt.cpp  ~/CSCE_A211        copies the file from my folder to yours
    4. cd ~/CSCE_A211            change to your CSCE_A211 folder
  3. At this point you should have a file named reverseIt.cpp in your CSCE_A211 folder.
    1. Use the commands you previously learned to compile and run the program. You had to copy the file from my directory to yours because my directory is set up with read-permission only.
    2. The program has an error.  You should be able to spot the error after running it. Fix the error and recompile the program.
    3. Show the reverseIt.cpp file on your computer to the TA or instructor.
  4. Additional Linux questions:
    1. What is the command to delete a file? For example, how would you delete the a.out file compiled in step 3?
    2. What command would you give to rename reverseIt.cpp to reverse.cpp?
    3. How do you display a long text file so it pauses on each screen?  You can practice by looking at the file /proc/cpuinfo which has information about the CPUs on the server, or the file ~kjmock/CSCE_A211/words.txt
    4. What do the up and down arrow keys do when you are in the shell?
    5. In the shell, type the ! character followed by a letter like g or l, as in !g or !l. You can experiment with other letters after the !. What does the ! do?
    6. Experiment with grep:
      1. grep is a program that allows you to search text using regular expressions (we will talk about regular expressions later). For now, you can use it to search for a pattern of text.
      2. A basic usage of the command is: grep  substring  target-file
      3. I have a list of 87314 words in the file ~kjmock/CSCE_A211/words.txt
      4. Use grep to find all words that contain "uaa" in this file. What are the words?
    7. Use a pipe:
      1. The command who will give a listing of users logged into the server, along with additional information such as their login time. 
      2. The command cut  -d  "  "  -f1 will only display the first word that is input, ignoring any other words on the same line (Note: the last flag is a lowercase letter f followed by the digit 1). If you run this from the command line it will wait for you to type in words and only display the first one. Type control-c to exit.
      3. Use the pipeline command | to link the above two commands together so you get a list of only the users that are currently logged onto the server.  Show the completed command to the TA or instructor.