0% found this document useful (0 votes)
23 views9 pages

Lab 02 Parta

Uploaded by

Ghadeer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views9 pages

Lab 02 Parta

Uploaded by

Ghadeer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Bachelor of Information Communications Technology

Bahrain Polytechnic

Unix Systems

Lab Session 2
Lab session 2 – Introduction to Command Line Interface 2

Lab session 2 – Introduction to Command Line Interface

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.

You must submit the following to the correct area in Moodle:

 A zip file named ‘lab02_studentID’ containing files lab2_q2.txt and lab2_q5.txt

Note: we will use psftp to retrieve the files from the student server to your windows machine.

Learning Outcomes Assessed

The following learning outcomes are being assessed in this lab session:

• Use the command-line on a UNIX system


• Manage a Linux server system (including files, processes, users)
Lab session 2 – Introduction to Command Line Interface 3

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.

Lab 2 – Getting started in 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:

Launch the application and complete the setting as below:


1.
Host name:
student1.bptest.cloud
Port: 22

2. You will be using


this often. It is
recommended you
save the setting for
future use. Click
‘Save’ and enter a
name for the saved
settings.

3. Finally, click ‘Open’


and you will be
connected to the unix
server.

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

Enter you username and then password:


Username: A20XXXXXX where XXXXX is the student number (remember, it is case sensitive)
Password: Enter your password.

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.

Your screen should look like:

To get the screen above change the window settings in PuTTY before you log in to 120x20.

You are now ready to start entering commands, enjoy!

Lab 2 – Basic Unix commands


The command line interface (sometimes called a terminal) allows you to enter text commands to the
Linux kernel and run programs. This terminal window is controlled by the program bash. When
Googling for help about a command, it might be of value to add bash in the search string.
Lab session 2 – Introduction to Command Line Interface 5

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:

1. a. Create a new directory named ‘lab2’ in the path /home/studentID


b. Change your directory to this new folder

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.

3. a. Change to the /home directory


b. List the standard files and directories in the current directory in a long format (i.e. includes
date and time)
c. List ALL files in the current directory in the long format
d. Repeat step ‘c’ but this time redirect the output to a file named ‘lab2_q3.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?

4. a. Display your current working directory


b. Try to enter the directory of a fellow student – can you ?
- What do you notice about the permissions of the directories?
c. Change your directory back to /home/yourstudentID/lab2

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.

Lab 2 – What you need to submit

 Retrieve the files lab2_q2.txt, lab2_q3.txt, lab2_q5.txt


 Zip them in a file named lab02_studentID
 Upload it to the lab 2 file upload area in Moodle.

Connect to Moodle using the standard web browser (http://www.tinyurl.com/moodlepoly) or


(http://webdev.polytechnic.bh/moodle)

Retrieving files using SFTP

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.

1. Download PSFTP from the following website,


https://www.puttygen.com/download-putty#PuTTY_for_windows

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

2. Launch the PSFTP application


You can type PSFTP at the windows search.

3. Type the following commands to retrieve your files. Note:- A SFTP cheat sheet is available on
Moodle which details other commands.

4. Type open student1.bptest.cloud ( or student2.bptest.cloud depending what server you


are working on)

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.

8. Type get /home/studentID/lab2/lab2_q2.txt ***This assumes your file is in this directory


9. Type get /home/studentID/lab2/lab2_q5.txt ***This assumes your file is in this directory

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

Retrieving files on a Mac

1 . Run terminal on your Mac PC.

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:

scp [email protected]:/home/username/lab2/lab2_q2.txt localpath/Desktop

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

You might also like