Lab 02 Parta
Lab 02 Parta
Bahrain Polytechnic
Unix Systems
Lab Session 2
Lab session 2 – Introduction to Command Line Interface 2
Introduction
The lab work consists of instructional material which is designed to get you familiar with the
software you will be using in the Unix systems course. Additionally, there will be some practical
tasks which will require you to upload a file to Moodle once complete.
Note: we will use psftp to retrieve the files from the student server to your windows machine.
The following learning outcomes are being assessed in this lab session:
Lab 2
You can log in to the Linux server via the command line or via the GUI using either PuTTY or Remote
Desktop respectively. PuTTY will take you into a command line interface (CLI) whereas Remote
Desktop will take you into a GUI set-up, known as Gnome desktop. It is possible to view both
sessions at the same time.
This lab will concentrate on using PuTTY.
Locate the PuTTY application on your computer. You can do a search if you don’t know what it looks
like. The icon is:
Once you are into the Unix session you will be faced with a window like below:
Lab session 2 – Introduction to Command Line Interface 4
If you have not changed your password, the default is ‘polytechnic’. If you are logging in for the first
time use the passwd command to change your password.
To get the screen above change the window settings in PuTTY before you log in to 120x20.
If you are ever unsure about what a command does, the ‘man’ command will give you some help (it
is short for manual). E.g. man ls you can also try ls - -help .
Using the Unix commands cheat sheet (available on Moodle), find out the correct commands to
complete the following tasks:
2. a. You are now located in the lab2 directory. Create a file named file1.txt. Create another file
named file2 (without the .txt). Use the ls command to check your work.
Whats the difference between the two files?
b. List the standard files and directories in the lab2 directory in a long format (i.e. includes date
and time)
c. List ALL files in the lab2 directory in the long format. What do you see that’s different to the
output from part b.
d. Repeat step ‘c’ but this time redirect the output to a file named ‘lab2_q2.txt’
Note: the redirect character is > ( the same as in Windows ) . To redirect the output of a
command X to file Y , you would enter X > Y.
Discussion: Can you think of a way to complete part 3 while remaining in your lab2 directory?
5. a. Type the following command: echo unix is great! and redirect it to a file named ‘lab2_q5.txt’.
This file should now be located in /home/studentID/lab2.
Note: the redirect character is > ( the same as in Windows ) . To redirect the output of a
command X to file Y , you would enter X > Y .
b. Confirm that the file has been created using the appropriate command and append the
output of this command to the lab2_q5.txt file.
Note: the append character is >> . To append the output of a command X to file Y that
already exists , you would enter X >> Y.
Verify your work : Inside your text document should be what is shown below:
Lab session 2 – Introduction to Command Line Interface 6
6. Retrieve the lab2_q2.txt, lab2_q3.txt, lab2_q5.txt files from the unix server using FTP. The
instructions on doing this can be found at the end of this lab.
SFTP (Secure File Transfer Protocol) is an application which will allow you to retrieive files which you
have created on the unix server.
*****For mac users you can transfer files directly from terminal. See the steps at the end of this lab.
Once the page is open, scroll down until use see the following screen. Click on the
appropriate link for your system, psftp.exe for 32 or 64 bit.
Lab session 2 – Introduction to Command Line Interface 7
3. Type the following commands to retrieve your files. Note:- A SFTP cheat sheet is available on
Moodle which details other commands.
5. You will be asked for a login as and password. These are the same as your PuTTY login.
6. You now need to set up a folder location which will receive any files you ftp across from the
server. You can use any folder to do this. E.g. If I want the “Documents” folder to be set as
the folder that will receive files I do the following:
a. Right click on the “Documents” folder and click properties. This will bring up the
following window. Click on the location tab.
Type the command lcd at the psftp prompt. Do not press Enter yet.
Lab session 2 – Introduction to Command Line Interface 8
Copy the location of the documents folder (Ctrl + C). Go back to psftp and paste(Right click)
after the lcd command so that your command looks like the following:
Press return and you should get the following success message:
7. Any files you FTP across will now be located in C:\Users\denis.mannning\Documents. If you
did not use the lcd command then all files will be dropped into the same directory as where
the PSFTP is located.
10. If you have executed the command correctly, the files lab2_q2.txt and lab2_q5.txt should
now be available in C:\Users\denis.mannning\Documents
2. Run the command ‘pwd’. The result of this command is your local path. Replace localpath in the
command below with the output of this command.
Lab session 2 – Introduction to Command Line Interface 9
3. Run this command in your terminal window. Where username is a capital ‘A’ followed by your
student id. Replace every instance of username in this command with your username. Notice there
is a space after lab2_q2.txt:
This will place your file on your Mac’s desktop. Run the command again changing the part that says
lab2_q2.txt to lab2_q5.txt