Lab #2, Wednesday 9/6

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 linuxcommand.org: http://linuxcommand.org/index.php.  You should read at least up to section 8 under "Learning the Shell" although it woudn't hurt to read more!

You can try commands out on transformer as you go.

Exercises

Save your answers in a file or just remember them. 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. 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.
  4. Copy the fixed reverseIt.cpp file from the linux server to your local machine.
    1. You must use a scp (secure copy) client. On Windows (and in the lab) you can use WinScp. It is available from http://winscp.net/eng/index.php. On a Mac or Unix system you can use scp from the terminal prompt or a nice free graphical client is Cyberduck: http://cyberduck.ch
    2. Using WinScp or a program like Cyberduck, you should see two windows. One contains your local files and the other are files on the linux system.  Navigate to your CSCE_A211 folder and copy reverseIt.cpp to your local machine by dragging the file to the window representing files on your computer.
    3. If you are using WinScp note that it includes a simple GUI editor - you can edit a file locally using the editor and WinScp will upload the file to the linux server for you.
    4. Show the reverseIt.cpp file on your computer to the TA or instructor.
  5. Additional Linux questions:
    1. What is the command to delete a file?
    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.
    4. 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 (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.