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!
We covered logging in on the previous lab. As a brief re-cap, you need to use a ssh client.
- The server is named uaa-transformer.duckdns.org
- Under Windows, a good ssh client is putty.
- On a Mac, you can open up a terminal window (Under applications/utilities) and run ssh -l username uaa-transformer.duckdns.org.
- If you are connecting from off-campus you have to install and log in using a VPN client. See https://anc-vpn01.uaa.alaska.edu for information.
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.
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.
- 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
- View the text file "programming_joke". What is the punchline?
- Make your own CSCE_A211 folder in your home directory and copy a file from my directory to yours with these commands:
- cd ~ changes to your home directory
- mkdir CSCE_A211 makes a folder named CSCE_A211
- cp ~kjmock/CSCE_A211/reverseIt.cpp ~/CSCE_A211 copies the file from my folder to yours
- cd ~/CSCE_A211 change to your CSCE_A211 folder
- At this point you should have a file named reverseIt.cpp in your CSCE_A211 folder.
- 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.
- The program has an error. You should be able to spot the error after running it. Fix the error and recompile the program.
- Copy the fixed reverseIt.cpp file from the linux server to your local machine.
- 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.
- 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.
- 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.
- Show the reverseIt.cpp file on your computer to the TA or instructor.
- Additional Linux questions:
- What is the command to delete a file?
- What command would you give to rename reverseIt.cpp to reverse.cpp?
- 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.
- Use a pipe:
- The command who will give a listing of users logged into the server, along with additional information such as their login time.
- 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.
- 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.