A1 Command Line - sheerazwalid/COMP-I GitHub Wiki
- Learn how to work from the Linux command line.
- Learn a simple approach to compile and run console programs written in C++.
When keyboards and monitors were first used in the early days of computers, all interaction with the computer was done by typing in characters and reading text displayed on the screen. There were no mice and no graphics other than characters were displayed in the screen. You can still interact with computers in this way; it is done using a program called a console or a terminal window. It turns out that this old style interface is very useful and frequently used to this day by programmers and system administrators. This is especially true for Linux systems, which are the predominate operating system for distributed computing resources on the Internet. For this reason, in this course we will learn how to use the command line interface.
You will submit your assignments using a Cloud9 workspace. Your instructor will use your email to send you an invitation to join the csusb team on Cloud9. When you receive this email, follow the link to create a free Cloud9 account. Then do the following.
- Create a new workspace within the csusb team with these options:
- Workspace name: cse201
- Template: Blank
- Access: Public
- Open the new workspace you created
- Click Share in the top right corner.
- Under the Invite People box, invite your TA with RW access. Their Cloud9 id can be found in the course syllabus.
At a minimum, you should learn the following UNIX commands for this course. Questions on these will appear on the exams. There are many other important UNIX commands but questions on them will not appear in any exam in this course.
command | description | example |
---|---|---|
pwd | print working directory | pwd |
cd | change directory | cd basics |
cp | copy file or directory | cp ex2.cpp ex3.cpp |
mv | move file or directory | mv hello.cpp bye.cpp |
rm | remove file or directory | rm a.out |
mkdir | make directory | mkdir basics |
rmdir | remove directory | rmdir basics |
You also need to know how to use the following special symbols:
symbol | meaning | example |
---|---|---|
. | current directory | ./a.out |
.. | parent directory | cd .. |
~ | home directory | rm ~/a.out |
For this assignment, you should complete the interactive Codecademy command line tutorial. You will need to create a free account with Codecademy for this purpose. The tutorial covers topics that will not appear on quizzes or exams; see the description above and the list of example quiz questions to understand what type of problems you are expected to solve from memory in this course.
command completion
One helpful feature of the terminal window is called command completion. If you press tab in the command line, the system will try to complete what you are typing by looking for a matching filename.
command history
Another helpful feature is called command history. This feature allows you to access a record of commands that you previously entered. Use the up and down arrow keys to scroll through the command history. Press enter at any previously entered command to run it again.
This section explains how to write, compile and run a simple C++ console program in your remote Cloud9 workspace. The program is called a hello program because when it runs, it prints hello.
Create a file named hello.cpp in your Cloud9 workspace and fill it with the following contents.
#include <iostream>
using namespace std;
int main(int argc, char * args[]) {
cout << "hello\n";
return 0;
}
From a Cloud9 terminal window, run the following command to compile hello.cpp.
c++ hello.cpp
The above command generates an executable file named a.out. To run this file, issue the following from the command line.
./a.out
Modify the source code in hello.cpp so that it displays Hello, Alice. Test that your changes produce an executable file that runs as expected.
To complete this lab, send an email to the teaching assistant that includes: your full name, a link to your Codecademy profile, and the URL of your Cloud9 cse201 workspace and CC the instructor in the email. You can find these email addresses in the course syllabus. The subject line of your email should be 201 Assignment: Command Line.
For full credit on this assignment, your Codecademy profile should list Learn the Command Line as a completed skill and the hello program in your Cloud9 workspace should compile and run.
Submission Notes
Include your full name in the body of your email.
To get the Codecademy profile link do the following.
- Log in to Codecademy.
- Move the mouse towards the upper-right hand corner of the screen. You should see a colorful, pixel icon that you can click on.
- It should contain options to "View Profile" or Logout. Click on "View Profile".
- After you are on your profile, copy the URL on top of the browser screen.
To get your Cloud9 cse201 workspace link, do the following.
After logging into Cloud9, open your cse201 workspace by clicking the Green Open button. Then copy the URL on top of the browser screen. It should look like the following: https://ide.c9.io/[cloud9_id]/cse201
, where [cloud9_id]
is represented as the username you chose when you made the account.
-
What is the Unix command to display your current working directory?
-
Show the Unix command to change the current directory to a folder named sam located in your home directory. Make no assumptions about your current location in the file system.
-
Suppose that you have a file named main.cpp that is in a folder in your home directory. Suppose that this folder is your current directory. Show the Unix command to copy main.cpp to your home directory.
-
Show the Unix command to list the contents of a folder in your home directory named lab1.
-
Suppose your home directory contains a folder named temp, and in this folder there is a file named a.out. Show the Unix command to delete (remove) the file a.out in the temp folder. Make no assumptions about your current directory.
-
Show the Unix command to list the contents of the parent folder of your current directory (i.e. the directory that contains your current directory).
-
Suppose that you have a file named main.cpp in your current directory. Show the Unix command to create a copy of this file named test.cpp. The copy should go into your current directory.
-
Show the Unix command to move a file named main.cpp from your home directory to a folder named lab1. Assume the lab1 folder is in your home directory. Make no assumptions about your current directory.
-
Suppose your home directory contains a folder named sam, and in this folder there is a file named hello.cpp. Show the Unix command to move hello.cpp into the home directory. Make no assumptions about your current directory.
-
Suppose that file a.out is in the parent directory of your current directory. Show the Unix command to delete (remove) this file.
-
Suppose that you have a file named main.cpp in your home directory. Show the Unix command to create a copy of this file named test.cpp. The copy should go into your current directory. Make no assumptions about the location of your current directory.
-
Suppose there is a folder named lab01 in your parent directory. Show the Unix command to create a folder named test within the lab01 folder. Make no assumptions about your current directory.