GE103 Lab 1 Assignment
This Lab assignment is intended to familiarize students with the use of UNIX-based operating systems.
The students will learn many basic concepts of Basic LINUX system commands and practice them using
the command line.
Steps Before the Starting of the Lab Session
Using a Guest account: This may be permitted in the first lab.
OR
Using the USER account: Make sure that you have your credentials, username and password for the
Linux machines ready. If you don’t have this information ready, get it from the IT department staff and
keep it securely. Using your user credentials, log into one of the lab machines and make sure that the
login is successful.
Screenshot of the home screen (Ubuntu) after login
Important Instructions to Note: -
1. Kindly pay careful attention to the information and instructions provided by TAs.
There would be a reference to <Rollno> in the document below.
This implies your roll number, e.g. 2025chb1234.
2. There are marks associated with your participation in the Lab and based on the
file submitted after lab completion.
3. If you face some difficulty and need assistance, seek the help of a TA. In some cases,
with the TA’s permission, you can take (minor) help from your classmate. In NO
situation should, use other students' work, else you will get a severe penalty.
4. For parts (C), (D), (E), (F), (G), record ALL commands and corresponding output
using the script command. Name your output file as rollno_lab1_part1. More
information on how to use the script is given in part (B). Show this file to the TAs
when you are done.
5. Points for part 1 (in lab) are 5, and points for part 2 (take-home) are 5, for a total of 10
points.
(A) Opening The Terminal Window
The terminal window provides a wide range of powerful capabilities for many processing needs. All the
instructions and commands for the present as well as future labs will be written in the Terminal window
itself. The following are some generic commands used for terminal processing.
1. Opening the Terminal Window: “ ctrl+alt+t ”
2. Closing the Terminal Window: “ ctrl+d ”
3. The Arrow Keys: Suppose you want to run a command that you ran a short while ago? If the
command is complicated, it would be nice not to have to retype it, and you don't have to! Within
the terminal window, this is accomplished using the up-arrow and down-arrow keys to
retrieve previous and next commands.
4. The history Command: But what if the command you want was several commands ago, say 20?
Who wants to type that many arrows? To see another option, first type the “history” to get a list of
the commands you have used most recently.
(B) Recording Linux Terminal Session
The script command records a session for you so that you can look at the output that you saw at the
time, and you can even record with timing so that you can have a real-time playback.
Record your terminal session
The “script” command makes a typescript of everything printed on your terminal. If the argument file is
given, the script saves all dialogue in the indicated file in the current directory. If no file name is given,
the typescript is saved in the default file typescript.
Use command: script <Rollno>_t1
i.e. script <Rollno>_t1 for terminal 1 and script <Rollnor>_t2 for terminal
After starting the recording, write some sample commands, as shown below. After writing all commands,
type “Ctrl+D” to finish recording.
To check the content after exiting a recorded session, you can use the cat command, e.g. cat
2025csz0001_t1.
Practice this by typing the commands below.
(C) Directory Navigation
1. Determine your current working directory: “ pwd ”
2. List the contents of the current directory: “ ls ”
3. List the contents of the current directory in long format: “ ls -l ”
4. Create a directory called learning: mkdir <Rollno> // e.g. mkdir 2025chb1234 5. Change
the current working directory to the new learning directory: cd <Rollno> 5. Create a Text
file. Using the “touch” command, just type “touch sample1.txt” command.
5. You may replace “sample.txt” filename with whatever you want to name your file.
You can also use the cat command to create a file. Use “cat > sample.txt”. After pressing Enter, you are not
returned to the terminal prompt. Instead, the cursor is placed on the next line, and you can start entering text
directly into your file. Type your lines of text, pressing Enter after each line. When you are done, press
Ctrl+D to exit the file and return to the prompt. For existing files, you can also use the cat command to view
the contents of your file. Just type the “cat sample.txt” command at the prompt, and then press Enter. *cat
command is further described in the upcoming sections.
6. List the files in learning in long format: “ ls -l ”
7. Change the working directory back to your home directory: “cd ..” OR “cd ” 8. Remove the
directory learning: “ rmdir ” . E.g. mkdir learning; ls ; rmdir learning; ls
(D) Viewing Files
1. List your files: “ ls”
2. View the file history using either less or more: “less history” OR “more history”
3. Using less, you will see a prompt containing the name of the file you are viewing, the number of the
current line, the total number of lines in the document, and the percentage of the file that has already been
viewed. Using more, you will see a prompt at the bottom of your screen which looks something like:
--More--(15%). Press Return key a few times to see a new line of text displayed on the screen each time.
4. Note how the percentage in the prompt changes. Press “space” once to see the next full page of the file.
5.Type “b” to go back one full page in the file.
6.Type “q” to quit the pager and return to the system prompt.
(E) Gedit command:
1. gedit can be used to create a new file or open an existing one with the help of a GUI text editor (gedit).
2. Create or open a file: “ gedit file.txt”
3. To open multiple files: “ gedit file1.txt file2.txt”
(F) Manipulating Files
Perform this Task before executing the following commands: Create one file and name it as “old”
1. List the files in your home directory: “ ls”
2. Copy “old” to a file called “new”. List your files to confirm that you have both old and new:
“cp old new”
“ls”
3. Rename the file old to ancient. List your files to confirm that the ancient and new exist.
“mv old ancient”
“ ls”
4. Remove the file ancient and then list your files to ensure it has been removed.
“rm ancient”
“ls”
5. Create a directory called myfolder. List your files to ensure that myfolder was created.
“mkdir myfolder”
“ls”
6. Set your current working directory to myfolder. Do not, however, type in the entire name of the directory.
7. Instead, type the first two letters and use Tab completion to fill in the rest of the file name:
“cd my<Tab> (Press the Tab key)”
8. Copy the file new from your home directory to myfolder: “cp ~/new new”
9. Using a wildcard, list all of the files that begin with the letter n: “ls n*”
10. Return to your home directory: “cd”
11. Remove the directory called myfolder and all its contents. List your files to ensure that it was removed:
“rm -r myfolder”
(G) Cat command:
Cat command allows us to create single or multiple files, view the contents of a file, concatenate files and redirect
output to the terminal or files.
1. General Syntax: Cat [option][file]
2. Create file: “cat >test.txt”
3. Awaits input from user, type desired text and press CTRL+D
4. Viewing single/multiple files: “cat test.txt [other files]”
5. Cat command with more or less option: “cat test.txt | more”
6. “ cat test.txt | less”
7. Use of the redirection operation:
a. Overwriting the contents of one file by writing into the other: “cat test.txt > test1.txt”
b. Appending the contents of one file at the end of the other: “cat test.txt >> test1.txt”
c. Redirecting the contents of a file into the terminal: “cat < test.txt”
(H) VI editor:
It is a basic UNIX editor. It has three modes: INSERT mode, EDIT mode and COMMAND mode.
Command mode: for interacting with the operating system
Letter Action
:r<file> Reads a file from disk into the vi editor
:w<file> Writes current file to disk
:wq Writes the file and quits vi
:q! Quits without writing file
Insert mode: for adding text to a file
Letter Action
i Starts inserting in front of the current cursor position.
I Starts adding at the front of the line.
a Starts adding after the cursor.
A Starts adding at the end of the line
o Starts opening a new line underneath the cursor
O Starts opening a line above the cursor
<esc> Gets out of insert mode
Edit mode: generally for moving the cursor and deleting stuff.
Letter Simple cursor movement
h Moves cursor left one space
j Moves cursor down one line
k Moves cursor up one line
l Moves cursor right one space
Letter Fast cursor movement
w Moves the cursor a full word at a time to the right
b Moves the cursor back to the left a word at a time
^ Moves the cursor to the front of a line
$ Moves the cursor to the end of a line
<ctrl>f Moves the cursor forward a full page of text at a time
<ctrl>b Moves the cursor backward a full page of text at a time
Letter Action
x Deletes the character under the cursor
dd Deletes the line where the cursor is located
ndd Delete n consecutive lines
r Replaces the character under cursor with the next character typed
J Joins current line with the one below
u Undoes the last edit operation
<ctrl>r Redo (undoes the last undo operation)
Letter Cut and paste operations
yy Copies or yanks a line (5yy yanks 5 lines)
p Puts the yanked text on the line below the cursor
P Puts the yanked text above the current line
Create a new text file with any name of your choice. Open the file using the vi editor. Practice each of
the above commands on this file. There is no need to submit anything for part H. Ask the TAs in case
of any questions/doubts.
Online help manual:
man command: used to display the online manual pages about a command. “man ls”
Explore various options listed in man pages.
Important Points
1. Online Coding Competitions: Codechef is a platform that gives you some programming-based
challenges and allows you to solve them after registering on it. People having experience of
programming can attempt a few problems of varying difficulty from it. The online link is given
below:
https://www.codechef.com/
2. To install any software on UNIX system use ‘apt-get install <package_name>’
(Internet connection is required).
References:
1. vi Editor: https://www.tjhsst.edu/~dhyatt/superap/vi.html
2. Cat commands: https://www.tecmint.com/13-basic-cat-command-examples-in-linux/
3. Gedit: https://help.ubuntu.com/community/gedit
4. Script: https://www.redhat.com/sysadmin/linux-script-command
5. https://www.howtogeek.com/199687/how-to-quickly-create-a-text-file-using-the-comman d-line-
in-linux/
Part 2 – Take Home
NOTE:
Put the output files of questions 1 and 2 in a folder named – rollno_lab1, compress the folder, and submit it
on Google Classroom (link to be shared soon).
Question 1: Create the following directory structure using UNIX commands. Replace P1.c with
file1.txt. For Departments, use the following: EE (Electrical), ME (Mechanical), MM (Materials &
Metallurgy), EP (Engineering Physics). Populate the directories BTech, MSR, PhD, and all their
files (file1.txt, UGCourse.txt, Syllabus.txt (appears twice), Score.txt, Student.txt, Roll.txt) for your
branch directory (EE or ME or MM or EP) only. Add suitable text to all the files. Except for the leaf
nodes in the above diagram, every heading represents a UNIX directory. Create the above directory
structure and the files (shown as the leaf nodes) using UNIX commands. Print this newly created
directory structure using the tree command. Using script, create an output file named - rollno_L1Q1.
This output file needs to contain the new directory structure that you just created.
Question 2: Perform the following tasks on the above created UNIX structure:
1. Go to the file file1.txt and print the current working directory.
2. List the contents of the directory “Departments” in long format.
3. Remove the directory MSR and show the change reflected.
4. Show the use of “more” command and all its features using the file UGCourse.txt.
5. Copy UGCourse.txt to a file called PGCourse.txt.
6. Rename PGCourse.txt to PhDCourse.txt and show the changes reflected.
7. Copy the file file1.txt from “Btech” Directory to the Academics Directory
8. List all the files under the Directory “PhD” that begin with “S”.
Using script, create an output file named – rollno_L1Q2. This output file needs to contain all the
commands and corresponding outputs.
Question 3: Create a file called “comments.text” using the vi editor.
/*********************************************
* Author:
* Entry number:
* Branch
* Date created:
*********************************************/
Close the file and exit vi. Next, open the file again using vi, and go ahead and fill in the required
details given above in this file.
How do you begin to enter text? How do you delete text if you made a mistake? Ensure that you
know this. Save your file and exit vi.
There is no need to submit anything for question 3. References:
1. vi Editor: https://www.tjhsst.edu/~dhyatt/superap/vi.html
2. Cat commands:
https://www.tecmint.com/13-basic-cat-command-examples-in-linux/
3. Gedit: https://help.ubuntu.com/community/gedit
4. Chmod: https://www.computerhope.com/unix/